From ca96362a5ff4720a9a4fc797da27bd7d7b760059 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Sun, 14 Apr 2019 22:04:46 +0100 Subject: [PATCH] Video --- .../Generated/Interfaces/ISteamVideo.cs | 69 +++++++++++++++++++ Facepunch.Steamworks/Redux/Steam.cs | 2 + Facepunch.Steamworks/Redux/Video.cs | 64 +++++++++++++++++ .../SteamNative/SteamNative.Structs.cs | 26 +++++++ Generator/CodeWriter/CodeWriter.cs | 1 + Generator/steam_api_missing.json | 5 ++ 6 files changed, 167 insertions(+) create mode 100644 Facepunch.Steamworks/Generated/Interfaces/ISteamVideo.cs create mode 100644 Facepunch.Steamworks/Redux/Video.cs diff --git a/Facepunch.Steamworks/Generated/Interfaces/ISteamVideo.cs b/Facepunch.Steamworks/Generated/Interfaces/ISteamVideo.cs new file mode 100644 index 0000000..00a59f9 --- /dev/null +++ b/Facepunch.Steamworks/Generated/Interfaces/ISteamVideo.cs @@ -0,0 +1,69 @@ +using System; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using SteamNative; + + +namespace Steamworks.Internal +{ + public class ISteamVideo : BaseSteamInterface + { + public override string InterfaceName => "STEAMVIDEO_INTERFACE_V002"; + + public override void InitInternals() + { + GetVideoURLDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 0) ); + IsBroadcastingDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 8) ); + GetOPFSettingsDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 16) ); + GetOPFStringForAppDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 24) ); + } + + #region FunctionMeta + [UnmanagedFunctionPointer( CallingConvention.ThisCall )] + public delegate void GetVideoURLDelegate( IntPtr self, AppId_t unVideoAppID ); + private GetVideoURLDelegate GetVideoURLDelegatePointer; + + #endregion + public void GetVideoURL( AppId_t unVideoAppID ) + { + GetVideoURLDelegatePointer( Self, unVideoAppID ); + } + + #region FunctionMeta + [UnmanagedFunctionPointer( CallingConvention.ThisCall )] + [return: MarshalAs( UnmanagedType.I1 )] + public delegate bool IsBroadcastingDelegate( IntPtr self, ref int pnNumViewers ); + private IsBroadcastingDelegate IsBroadcastingDelegatePointer; + + #endregion + public bool IsBroadcasting( ref int pnNumViewers ) + { + return IsBroadcastingDelegatePointer( Self, ref pnNumViewers ); + } + + #region FunctionMeta + [UnmanagedFunctionPointer( CallingConvention.ThisCall )] + public delegate void GetOPFSettingsDelegate( IntPtr self, AppId_t unVideoAppID ); + private GetOPFSettingsDelegate GetOPFSettingsDelegatePointer; + + #endregion + public void GetOPFSettings( AppId_t unVideoAppID ) + { + GetOPFSettingsDelegatePointer( Self, unVideoAppID ); + } + + #region FunctionMeta + [UnmanagedFunctionPointer( CallingConvention.ThisCall )] + [return: MarshalAs( UnmanagedType.I1 )] + public delegate bool GetOPFStringForAppDelegate( IntPtr self, AppId_t unVideoAppID, StringBuilder pchBuffer, ref int pnBufferSize ); + private GetOPFStringForAppDelegate GetOPFStringForAppDelegatePointer; + + #endregion + public bool GetOPFStringForApp( AppId_t unVideoAppID, StringBuilder pchBuffer, ref int pnBufferSize ) + { + return GetOPFStringForAppDelegatePointer( Self, unVideoAppID, pchBuffer, ref pnBufferSize ); + } + + } +} diff --git a/Facepunch.Steamworks/Redux/Steam.cs b/Facepunch.Steamworks/Redux/Steam.cs index 18dd68a..3454a48 100644 --- a/Facepunch.Steamworks/Redux/Steam.cs +++ b/Facepunch.Steamworks/Redux/Steam.cs @@ -34,6 +34,8 @@ public static void Init( uint appid ) Apps.InstallEvents(); Utils.InstallEvents(); Parental.InstallEvents(); + Music.InstallEvents(); + Video.InstallEvents(); } internal static void RegisterCallback( IntPtr intPtr, int callbackId ) diff --git a/Facepunch.Steamworks/Redux/Video.cs b/Facepunch.Steamworks/Redux/Video.cs new file mode 100644 index 0000000..ce324da --- /dev/null +++ b/Facepunch.Steamworks/Redux/Video.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using SteamNative; + +namespace Steamworks +{ + /// + /// Undocumented Parental Settings + /// + public static class Video + { + static Internal.ISteamVideo _internal; + internal static Internal.ISteamVideo Internal + { + get + { + if ( _internal == null ) + _internal = new Internal.ISteamVideo(); + + return _internal; + } + } + + internal static void InstallEvents() + { + new Event( x => OnBroadcastStarted?.Invoke() ); + new Event( x => OnBroadcastStopped?.Invoke( x.Result ) ); + } + + public static event Action OnBroadcastStarted; + public static event Action OnBroadcastStopped; + + /// + /// Return true if currently using Steam's live broadcasting + /// + public static bool IsBroadcasting + { + get + { + int viewers = 0; + return Internal.IsBroadcasting( ref viewers ); + } + } + + /// + /// If we're broadcasting, will return the number of live viewers + /// + public static int NumViewers + { + get + { + int viewers = 0; + + if ( !Internal.IsBroadcasting( ref viewers ) ) + return 0; + + return viewers; + } + } + } +} \ No newline at end of file diff --git a/Facepunch.Steamworks/SteamNative/SteamNative.Structs.cs b/Facepunch.Steamworks/SteamNative/SteamNative.Structs.cs index a079f0a..b608295 100644 --- a/Facepunch.Steamworks/SteamNative/SteamNative.Structs.cs +++ b/Facepunch.Steamworks/SteamNative/SteamNative.Structs.cs @@ -6841,6 +6841,31 @@ public struct Pack8 #endregion } + public struct BroadcastUploadStart_t : Steamworks.ISteamCallback + { + + #region ISteamCallback + public int GetCallbackId() => CallbackIdentifiers.ClientVideo + 4; + public int GetStructSize() => System.Runtime.InteropServices.Marshal.SizeOf( Platform.PackSmall ? typeof(Pack4) : typeof(Pack8) ); + public Steamworks.ISteamCallback Fill( IntPtr p ) => Platform.PackSmall ? ((BroadcastUploadStart_t)(Pack4) Marshal.PtrToStructure( p, typeof(Pack4) )) : ((BroadcastUploadStart_t)(Pack8) Marshal.PtrToStructure( p, typeof(Pack8) )); + #endregion + #region Packed Versions + [StructLayout( LayoutKind.Sequential, Pack = 4 )] + public struct Pack4 + { + + public static implicit operator BroadcastUploadStart_t ( BroadcastUploadStart_t.Pack4 d ) => new BroadcastUploadStart_t{ }; + } + + [StructLayout( LayoutKind.Sequential, Pack = 8 )] + public struct Pack8 + { + + public static implicit operator BroadcastUploadStart_t ( BroadcastUploadStart_t.Pack8 d ) => new BroadcastUploadStart_t{ }; + } + #endregion + } + public struct NewUrlLaunchParameters_t : Steamworks.ISteamCallback { @@ -7484,6 +7509,7 @@ internal static void RegisterCallbacks( Facepunch.Steamworks.BaseSteamworks stea new CallbackHandle( steamworks ); new CallbackHandle( steamworks ); new CallbackHandle( steamworks ); + new CallbackHandle( steamworks ); new CallbackHandle( steamworks ); new CallbackHandle( steamworks ); new CallbackHandle( steamworks ); diff --git a/Generator/CodeWriter/CodeWriter.cs b/Generator/CodeWriter/CodeWriter.cs index db12e2e..3e20a2a 100644 --- a/Generator/CodeWriter/CodeWriter.cs +++ b/Generator/CodeWriter/CodeWriter.cs @@ -96,6 +96,7 @@ public void ToFolder( string folder ) GenerateVTableClass( "ISteamUtils", $"{folder}../Generated/Interfaces/ISteamUtils.cs" ); GenerateVTableClass( "ISteamParentalSettings", $"{folder}../Generated/Interfaces/ISteamParentalSettings.cs" ); GenerateVTableClass( "ISteamMusic", $"{folder}../Generated/Interfaces/ISteamMusic.cs" ); + GenerateVTableClass( "ISteamVideo", $"{folder}../Generated/Interfaces/ISteamVideo.cs" ); } } diff --git a/Generator/steam_api_missing.json b/Generator/steam_api_missing.json index e1e9189..28ead23 100644 --- a/Generator/steam_api_missing.json +++ b/Generator/steam_api_missing.json @@ -7,6 +7,11 @@ "struct": "PlaybackStatusHasChanged_t", "fields": [ ] }, + + { + "struct": "BroadcastUploadStart_t", + "fields": [ ] + }, { "struct": "NewUrlLaunchParameters_t",