From f495d18eceedf541184bdeab07dcb0b52b04dabc Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Sun, 23 Feb 2020 18:58:50 +0000 Subject: [PATCH] Added SteamRemotePlay --- .../Facepunch.Steamworks.TestWin32.csproj | 1 + .../Facepunch.Steamworks.TestWin64.csproj | 1 + Facepunch.Steamworks.Test/RemotePlayTest.cs | 30 ++++++++++ Facepunch.Steamworks/Generated/SteamEnums.cs | 2 +- Facepunch.Steamworks/SteamClient.cs | 1 + Facepunch.Steamworks/SteamRemotePlay.cs | 58 +++++++++++++++++++ .../Structs/RemotePlaySession.cs | 38 ++++++++++++ Generator/Cleanup.cs | 1 + 8 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 Facepunch.Steamworks.Test/RemotePlayTest.cs create mode 100644 Facepunch.Steamworks/SteamRemotePlay.cs create mode 100644 Facepunch.Steamworks/Structs/RemotePlaySession.cs diff --git a/Facepunch.Steamworks.Test/Facepunch.Steamworks.TestWin32.csproj b/Facepunch.Steamworks.Test/Facepunch.Steamworks.TestWin32.csproj index 1061f65..6919bc6 100644 --- a/Facepunch.Steamworks.Test/Facepunch.Steamworks.TestWin32.csproj +++ b/Facepunch.Steamworks.Test/Facepunch.Steamworks.TestWin32.csproj @@ -108,6 +108,7 @@ + diff --git a/Facepunch.Steamworks.Test/Facepunch.Steamworks.TestWin64.csproj b/Facepunch.Steamworks.Test/Facepunch.Steamworks.TestWin64.csproj index 17b5a62..4f169bf 100644 --- a/Facepunch.Steamworks.Test/Facepunch.Steamworks.TestWin64.csproj +++ b/Facepunch.Steamworks.Test/Facepunch.Steamworks.TestWin64.csproj @@ -101,6 +101,7 @@ + diff --git a/Facepunch.Steamworks.Test/RemotePlayTest.cs b/Facepunch.Steamworks.Test/RemotePlayTest.cs new file mode 100644 index 0000000..64e3add --- /dev/null +++ b/Facepunch.Steamworks.Test/RemotePlayTest.cs @@ -0,0 +1,30 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Steamworks +{ + [TestClass] + [DeploymentItem( "steam_api64.dll" )] + [DeploymentItem( "steam_api.dll" )] + public class RemotePlayTest + { + [TestMethod] + public void BasicUsability() + { + Console.WriteLine( $"Sessions: {SteamRemotePlay.SessionCount}" ); + + var session = SteamRemotePlay.GetSession( 4 ); + + Assert.IsFalse( session.IsValid ); + Assert.IsFalse( session.SteamId.IsValid ); + } + + } + +} diff --git a/Facepunch.Steamworks/Generated/SteamEnums.cs b/Facepunch.Steamworks/Generated/SteamEnums.cs index e207d1c..ef706c9 100644 --- a/Facepunch.Steamworks/Generated/SteamEnums.cs +++ b/Facepunch.Steamworks/Generated/SteamEnums.cs @@ -1927,7 +1927,7 @@ namespace Steamworks // // ESteamDeviceFormFactor // - internal enum SteamDeviceFormFactor : int + public enum SteamDeviceFormFactor : int { Unknown = 0, Phone = 1, diff --git a/Facepunch.Steamworks/SteamClient.cs b/Facepunch.Steamworks/SteamClient.cs index 1d10164..1937b4d 100644 --- a/Facepunch.Steamworks/SteamClient.cs +++ b/Facepunch.Steamworks/SteamClient.cs @@ -55,6 +55,7 @@ namespace Steamworks AddInterface(); AddInterface(); AddInterface(); + AddInterface(); if ( asyncCallbacks ) { diff --git a/Facepunch.Steamworks/SteamRemotePlay.cs b/Facepunch.Steamworks/SteamRemotePlay.cs new file mode 100644 index 0000000..48a1945 --- /dev/null +++ b/Facepunch.Steamworks/SteamRemotePlay.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using Steamworks.Data; + +namespace Steamworks +{ + /// + /// Functions that provide information about Steam Remote Play sessions, streaming your game content to another computer or to a Steam Link app or hardware. + /// + public class SteamRemotePlay : SteamClientClass + { + internal static ISteamRemotePlay Internal => Interface as ISteamRemotePlay; + + internal override void InitializeInterface( bool server ) + { + SetInterface( server, new ISteamRemotePlay( server ) ); + + InstallEvents( server ); + } + + internal void InstallEvents( bool server ) + { + Dispatch.Install( x => OnSessionConnected?.Invoke( x.SessionID ), server ); + Dispatch.Install( x => OnSessionDisconnected?.Invoke( x.SessionID ), server ); + } + + /// + /// Called when a session is connected + /// + public static event Action OnSessionConnected; + + /// + /// Called when a session becomes disconnected + /// + public static event Action OnSessionDisconnected; + + /// + /// Get the number of currently connected Steam Remote Play sessions + /// + public static int SessionCount => (int) Internal.GetSessionCount(); + + /// + /// Get the currently connected Steam Remote Play session ID at the specified index. + /// IsValid will return false if it's out of bounds + /// + public static RemotePlaySession GetSession( int index ) => (RemotePlaySession) Internal.GetSessionID( index ).Value; + + + /// + /// Invite a friend to Remote Play Together + /// This returns false if the invite can't be sent + /// + public static bool SendInvite( SteamId steamid ) => Internal.BSendRemotePlayTogetherInvite( steamid ); + } +} diff --git a/Facepunch.Steamworks/Structs/RemotePlaySession.cs b/Facepunch.Steamworks/Structs/RemotePlaySession.cs new file mode 100644 index 0000000..f39693f --- /dev/null +++ b/Facepunch.Steamworks/Structs/RemotePlaySession.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; + +namespace Steamworks.Data +{ + /// + /// Represents a RemotePlaySession from the SteamRemotePlay interface + /// + public struct RemotePlaySession + { + public uint Id { get; set; } + + public override string ToString() => Id.ToString(); + public static implicit operator RemotePlaySession( uint value ) => new RemotePlaySession() { Id = value }; + public static implicit operator uint( RemotePlaySession value ) => value.Id; + + /// + /// Returns true if this session was valid when created. This will stay true even + /// after disconnection - so be sure to watch SteamRemotePlay.OnSessionDisconnected + /// + public bool IsValid => Id > 0; + + /// + /// Get the SteamID of the connected user + /// + public SteamId SteamId => SteamRemotePlay.Internal.GetSessionSteamID( Id ); + + /// + /// Get the name of the session client device + /// + public string ClientName => SteamRemotePlay.Internal.GetSessionClientName( Id ); + + /// + /// Get the name of the session client device + /// + public SteamDeviceFormFactor FormFactor => SteamRemotePlay.Internal.GetSessionClientFormFactor( Id ); + } +} diff --git a/Generator/Cleanup.cs b/Generator/Cleanup.cs index bbd3757..df6701b 100644 --- a/Generator/Cleanup.cs +++ b/Generator/Cleanup.cs @@ -129,6 +129,7 @@ public static class Cleanup if ( name == "PingLocation" ) return "public"; if ( name == "ConnectionState" ) return "public"; if ( name == "SteamNetworkingAvailability" ) return "public"; + if ( name == "SteamDeviceFormFactor" ) return "public"; return "internal"; }