From 7a04765805cd4d6a67c87718b182cc25bd6fcc64 Mon Sep 17 00:00:00 2001 From: Rubat Date: Thu, 20 May 2021 19:04:12 +0300 Subject: [PATCH] Handle Steam not running better --- Facepunch.Steamworks/SteamApps.cs | 5 ++++- Facepunch.Steamworks/SteamClient.cs | 11 +++++++++-- Facepunch.Steamworks/SteamFriends.cs | 5 ++++- Facepunch.Steamworks/SteamInput.cs | 8 ++++++-- Facepunch.Steamworks/SteamInventory.cs | 5 ++++- Facepunch.Steamworks/SteamMatchmaking.cs | 5 ++++- Facepunch.Steamworks/SteamMatchmakingServers.cs | 5 ++++- Facepunch.Steamworks/SteamMusic.cs | 4 +++- Facepunch.Steamworks/SteamNetworking.cs | 5 ++++- Facepunch.Steamworks/SteamNetworkingSockets.cs | 5 ++++- Facepunch.Steamworks/SteamNetworkingUtils.cs | 6 +++++- Facepunch.Steamworks/SteamParental.cs | 6 +++++- Facepunch.Steamworks/SteamParties.cs | 6 +++++- Facepunch.Steamworks/SteamRemotePlay.cs | 5 ++++- Facepunch.Steamworks/SteamRemoteStorage.cs | 5 ++++- Facepunch.Steamworks/SteamScreenshots.cs | 6 +++++- Facepunch.Steamworks/SteamServer.cs | 6 +++++- Facepunch.Steamworks/SteamServerStats.cs | 5 ++++- Facepunch.Steamworks/SteamUgc.cs | 6 +++++- Facepunch.Steamworks/SteamUser.cs | 6 +++++- Facepunch.Steamworks/SteamUserStats.cs | 6 +++++- Facepunch.Steamworks/SteamUtils.cs | 6 +++++- Facepunch.Steamworks/SteamVideo.cs | 6 +++++- Facepunch.Steamworks/Utility/SteamInterface.cs | 14 +++++++------- 24 files changed, 115 insertions(+), 32 deletions(-) diff --git a/Facepunch.Steamworks/SteamApps.cs b/Facepunch.Steamworks/SteamApps.cs index 2610e02..339bb1c 100644 --- a/Facepunch.Steamworks/SteamApps.cs +++ b/Facepunch.Steamworks/SteamApps.cs @@ -15,9 +15,12 @@ public class SteamApps : SteamSharedClass { internal static ISteamApps Internal => Interface as ISteamApps; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamApps( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; + + return true; } internal static void InstallEvents() diff --git a/Facepunch.Steamworks/SteamClient.cs b/Facepunch.Steamworks/SteamClient.cs index 73d61cc..be098d5 100644 --- a/Facepunch.Steamworks/SteamClient.cs +++ b/Facepunch.Steamworks/SteamClient.cs @@ -73,8 +73,15 @@ public static void Init( uint appid, bool asyncCallbacks = true ) internal static void AddInterface() where T : SteamClass, new() { var t = new T(); - t.InitializeInterface( false ); - openInterfaces.Add( t ); + bool valid = t.InitializeInterface( false ); + if ( valid ) + { + openInterfaces.Add( t ); + } + else + { + t.DestroyInterface( false ); + } } static readonly List openInterfaces = new List(); diff --git a/Facepunch.Steamworks/SteamFriends.cs b/Facepunch.Steamworks/SteamFriends.cs index a07199d..a701269 100644 --- a/Facepunch.Steamworks/SteamFriends.cs +++ b/Facepunch.Steamworks/SteamFriends.cs @@ -14,13 +14,16 @@ public class SteamFriends : SteamClientClass { internal static ISteamFriends Internal => Interface as ISteamFriends; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamFriends( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; richPresence = new Dictionary(); InstallEvents(); + + return true; } static Dictionary richPresence; diff --git a/Facepunch.Steamworks/SteamInput.cs b/Facepunch.Steamworks/SteamInput.cs index d55e523..269bce0 100644 --- a/Facepunch.Steamworks/SteamInput.cs +++ b/Facepunch.Steamworks/SteamInput.cs @@ -1,4 +1,5 @@ -using Steamworks.Data; +using System; +using Steamworks.Data; using System.Collections.Generic; namespace Steamworks @@ -7,9 +8,12 @@ public class SteamInput : SteamClientClass { internal static ISteamInput Internal => Interface as ISteamInput; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamInput( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; + + return true; } internal const int STEAM_CONTROLLER_MAX_COUNT = 16; diff --git a/Facepunch.Steamworks/SteamInventory.cs b/Facepunch.Steamworks/SteamInventory.cs index 79fa3ac..85203e0 100644 --- a/Facepunch.Steamworks/SteamInventory.cs +++ b/Facepunch.Steamworks/SteamInventory.cs @@ -16,11 +16,14 @@ public class SteamInventory : SteamSharedClass { internal static ISteamInventory Internal => Interface as ISteamInventory; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamInventory( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; InstallEvents( server ); + + return true; } internal static void InstallEvents( bool server ) diff --git a/Facepunch.Steamworks/SteamMatchmaking.cs b/Facepunch.Steamworks/SteamMatchmaking.cs index 9c5b2bf..c0ce764 100644 --- a/Facepunch.Steamworks/SteamMatchmaking.cs +++ b/Facepunch.Steamworks/SteamMatchmaking.cs @@ -14,11 +14,14 @@ public class SteamMatchmaking : SteamClientClass { internal static ISteamMatchmaking Internal => Interface as ISteamMatchmaking; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamMatchmaking( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; InstallEvents(); + + return true; } /// diff --git a/Facepunch.Steamworks/SteamMatchmakingServers.cs b/Facepunch.Steamworks/SteamMatchmakingServers.cs index c1af07a..448d9b4 100644 --- a/Facepunch.Steamworks/SteamMatchmakingServers.cs +++ b/Facepunch.Steamworks/SteamMatchmakingServers.cs @@ -14,9 +14,12 @@ internal class SteamMatchmakingServers : SteamClientClass Interface as ISteamMatchmakingServers; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamMatchmakingServers( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; + + return true; } } } \ No newline at end of file diff --git a/Facepunch.Steamworks/SteamMusic.cs b/Facepunch.Steamworks/SteamMusic.cs index 1ef38f8..a6f2616 100644 --- a/Facepunch.Steamworks/SteamMusic.cs +++ b/Facepunch.Steamworks/SteamMusic.cs @@ -17,11 +17,13 @@ public class SteamMusic : SteamClientClass { internal static ISteamMusic Internal => Interface as ISteamMusic; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamMusic( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; InstallEvents(); + return true; } internal static void InstallEvents() diff --git a/Facepunch.Steamworks/SteamNetworking.cs b/Facepunch.Steamworks/SteamNetworking.cs index 05e4c17..78940c9 100644 --- a/Facepunch.Steamworks/SteamNetworking.cs +++ b/Facepunch.Steamworks/SteamNetworking.cs @@ -12,11 +12,14 @@ public class SteamNetworking : SteamSharedClass { internal static ISteamNetworking Internal => Interface as ISteamNetworking; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamNetworking( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; InstallEvents( server ); + + return true; } internal static void InstallEvents( bool server ) diff --git a/Facepunch.Steamworks/SteamNetworkingSockets.cs b/Facepunch.Steamworks/SteamNetworkingSockets.cs index 7e1dd8d..cf70a58 100644 --- a/Facepunch.Steamworks/SteamNetworkingSockets.cs +++ b/Facepunch.Steamworks/SteamNetworkingSockets.cs @@ -31,10 +31,13 @@ public static NetIdentity Identity } } - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamNetworkingSockets( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; + InstallEvents( server ); + return true; } #region SocketInterface diff --git a/Facepunch.Steamworks/SteamNetworkingUtils.cs b/Facepunch.Steamworks/SteamNetworkingUtils.cs index ecd228d..6d86951 100644 --- a/Facepunch.Steamworks/SteamNetworkingUtils.cs +++ b/Facepunch.Steamworks/SteamNetworkingUtils.cs @@ -14,10 +14,14 @@ public class SteamNetworkingUtils : SteamSharedClass { internal static ISteamNetworkingUtils Internal => Interface as ISteamNetworkingUtils; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamNetworkingUtils( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; + InstallCallbacks( server ); + + return true; } static void InstallCallbacks( bool server ) diff --git a/Facepunch.Steamworks/SteamParental.cs b/Facepunch.Steamworks/SteamParental.cs index b746ca3..7ab5a1c 100644 --- a/Facepunch.Steamworks/SteamParental.cs +++ b/Facepunch.Steamworks/SteamParental.cs @@ -14,10 +14,14 @@ public class SteamParental : SteamSharedClass { internal static ISteamParentalSettings Internal => Interface as ISteamParentalSettings; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamParentalSettings( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; + InstallEvents( server ); + + return true; } internal static void InstallEvents( bool server ) diff --git a/Facepunch.Steamworks/SteamParties.cs b/Facepunch.Steamworks/SteamParties.cs index aef57bb..3cb897d 100644 --- a/Facepunch.Steamworks/SteamParties.cs +++ b/Facepunch.Steamworks/SteamParties.cs @@ -17,10 +17,14 @@ public class SteamParties : SteamClientClass { internal static ISteamParties Internal => Interface as ISteamParties; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamParties( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; + InstallEvents( server ); + + return true; } internal void InstallEvents( bool server ) diff --git a/Facepunch.Steamworks/SteamRemotePlay.cs b/Facepunch.Steamworks/SteamRemotePlay.cs index 48a1945..5452c2c 100644 --- a/Facepunch.Steamworks/SteamRemotePlay.cs +++ b/Facepunch.Steamworks/SteamRemotePlay.cs @@ -14,11 +14,14 @@ public class SteamRemotePlay : SteamClientClass { internal static ISteamRemotePlay Internal => Interface as ISteamRemotePlay; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamRemotePlay( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; InstallEvents( server ); + + return true; } internal void InstallEvents( bool server ) diff --git a/Facepunch.Steamworks/SteamRemoteStorage.cs b/Facepunch.Steamworks/SteamRemoteStorage.cs index 4754493..22976fb 100644 --- a/Facepunch.Steamworks/SteamRemoteStorage.cs +++ b/Facepunch.Steamworks/SteamRemoteStorage.cs @@ -14,9 +14,12 @@ public class SteamRemoteStorage : SteamClientClass { internal static ISteamRemoteStorage Internal => Interface as ISteamRemoteStorage; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamRemoteStorage( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; + + return true; } diff --git a/Facepunch.Steamworks/SteamScreenshots.cs b/Facepunch.Steamworks/SteamScreenshots.cs index 3db167f..78acf98 100644 --- a/Facepunch.Steamworks/SteamScreenshots.cs +++ b/Facepunch.Steamworks/SteamScreenshots.cs @@ -14,10 +14,14 @@ public class SteamScreenshots : SteamClientClass { internal static ISteamScreenshots Internal => Interface as ISteamScreenshots; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamScreenshots( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; + InstallEvents(); + + return true; } internal static void InstallEvents() diff --git a/Facepunch.Steamworks/SteamServer.cs b/Facepunch.Steamworks/SteamServer.cs index b892760..b2056a4 100644 --- a/Facepunch.Steamworks/SteamServer.cs +++ b/Facepunch.Steamworks/SteamServer.cs @@ -14,10 +14,14 @@ public partial class SteamServer : SteamServerClass { internal static ISteamGameServer Internal => Interface as ISteamGameServer; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamGameServer( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; + InstallEvents(); + + return true; } public static bool IsValid => Internal != null && Internal.IsValid; diff --git a/Facepunch.Steamworks/SteamServerStats.cs b/Facepunch.Steamworks/SteamServerStats.cs index 2de7b0f..bdee0f7 100644 --- a/Facepunch.Steamworks/SteamServerStats.cs +++ b/Facepunch.Steamworks/SteamServerStats.cs @@ -11,9 +11,12 @@ public class SteamServerStats : SteamServerClass { internal static ISteamGameServerStats Internal => Interface as ISteamGameServerStats; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamGameServerStats( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; + + return true; } diff --git a/Facepunch.Steamworks/SteamUgc.cs b/Facepunch.Steamworks/SteamUgc.cs index a36fb64..b12c789 100644 --- a/Facepunch.Steamworks/SteamUgc.cs +++ b/Facepunch.Steamworks/SteamUgc.cs @@ -17,10 +17,14 @@ public class SteamUGC : SteamSharedClass { internal static ISteamUGC Internal => Interface as ISteamUGC; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamUGC( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; + InstallEvents( server ); + + return true; } internal static void InstallEvents( bool server ) diff --git a/Facepunch.Steamworks/SteamUser.cs b/Facepunch.Steamworks/SteamUser.cs index e481d84..43cadd1 100644 --- a/Facepunch.Steamworks/SteamUser.cs +++ b/Facepunch.Steamworks/SteamUser.cs @@ -17,13 +17,17 @@ public class SteamUser : SteamClientClass { internal static ISteamUser Internal => Interface as ISteamUser; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamUser( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; + InstallEvents(); richPresence = new Dictionary(); SampleRate = OptimalSampleRate; + + return true; } static Dictionary richPresence; diff --git a/Facepunch.Steamworks/SteamUserStats.cs b/Facepunch.Steamworks/SteamUserStats.cs index 97bbb31..81eb176 100644 --- a/Facepunch.Steamworks/SteamUserStats.cs +++ b/Facepunch.Steamworks/SteamUserStats.cs @@ -11,11 +11,15 @@ public class SteamUserStats : SteamClientClass { internal static ISteamUserStats Internal => Interface as ISteamUserStats; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamUserStats( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; + InstallEvents(); RequestCurrentStats(); + + return true; } public static bool StatsRecieved { get; internal set; } diff --git a/Facepunch.Steamworks/SteamUtils.cs b/Facepunch.Steamworks/SteamUtils.cs index 9d3eea0..74c4480 100644 --- a/Facepunch.Steamworks/SteamUtils.cs +++ b/Facepunch.Steamworks/SteamUtils.cs @@ -14,10 +14,14 @@ public class SteamUtils : SteamSharedClass { internal static ISteamUtils Internal => Interface as ISteamUtils; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamUtils( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; + InstallEvents( server ); + + return true; } internal static void InstallEvents( bool server ) diff --git a/Facepunch.Steamworks/SteamVideo.cs b/Facepunch.Steamworks/SteamVideo.cs index ac578d3..5bfcabb 100644 --- a/Facepunch.Steamworks/SteamVideo.cs +++ b/Facepunch.Steamworks/SteamVideo.cs @@ -14,10 +14,14 @@ public class SteamVideo : SteamClientClass { internal static ISteamVideo Internal => Interface as ISteamVideo; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamVideo( server ) ); + if ( Interface.Self == IntPtr.Zero ) return false; + InstallEvents(); + + return true; } internal static void InstallEvents() diff --git a/Facepunch.Steamworks/Utility/SteamInterface.cs b/Facepunch.Steamworks/Utility/SteamInterface.cs index a8b13da..e683cd3 100644 --- a/Facepunch.Steamworks/Utility/SteamInterface.cs +++ b/Facepunch.Steamworks/Utility/SteamInterface.cs @@ -55,7 +55,7 @@ internal void ShutdownInterface() public abstract class SteamClass { - internal abstract void InitializeInterface( bool server ); + internal abstract bool InitializeInterface( bool server ); internal abstract void DestroyInterface( bool server ); } @@ -65,9 +65,9 @@ public class SteamSharedClass : SteamClass internal static SteamInterface InterfaceClient; internal static SteamInterface InterfaceServer; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { - + return false; } internal virtual void SetInterface( bool server, SteamInterface iface ) @@ -101,9 +101,9 @@ public class SteamClientClass : SteamClass { internal static SteamInterface Interface; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { - + return false; } internal virtual void SetInterface( bool server, SteamInterface iface ) @@ -124,9 +124,9 @@ public class SteamServerClass : SteamClass { internal static SteamInterface Interface; - internal override void InitializeInterface( bool server ) + internal override bool InitializeInterface( bool server ) { - + return false; } internal virtual void SetInterface( bool server, SteamInterface iface )