From bc9801c36abebb0191f65fc6be176c92cd529888 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Sun, 23 Feb 2020 11:25:56 +0000 Subject: [PATCH] Prefer use client interface if both exist (this might need a big change at some point) --- Facepunch.Steamworks/SteamApps.cs | 8 ++- Facepunch.Steamworks/SteamClient.cs | 2 +- Facepunch.Steamworks/SteamFriends.cs | 7 ++- Facepunch.Steamworks/SteamInput.cs | 7 ++- Facepunch.Steamworks/SteamInventory.cs | 23 +++++---- Facepunch.Steamworks/SteamMatchmaking.cs | 8 ++- .../SteamMatchmakingServers.cs | 7 ++- Facepunch.Steamworks/SteamMusic.cs | 7 ++- Facepunch.Steamworks/SteamNetworking.cs | 15 +++--- .../SteamNetworkingSockets.cs | 13 +++-- Facepunch.Steamworks/SteamNetworkingUtils.cs | 12 ++--- Facepunch.Steamworks/SteamParental.cs | 14 +++-- Facepunch.Steamworks/SteamParties.cs | 15 +++--- Facepunch.Steamworks/SteamRemoteStorage.cs | 8 +-- Facepunch.Steamworks/SteamScreenshots.cs | 7 ++- Facepunch.Steamworks/SteamServer.cs | 14 ++--- Facepunch.Steamworks/SteamServerStats.cs | 8 +-- Facepunch.Steamworks/SteamUgc.cs | 13 +++-- Facepunch.Steamworks/SteamUser.cs | 7 ++- Facepunch.Steamworks/SteamUserStats.cs | 8 ++- Facepunch.Steamworks/SteamUtils.cs | 20 ++++---- Facepunch.Steamworks/SteamVideo.cs | 8 ++- .../Utility/SteamInterface.cs | 51 ++++++++++++++++--- 23 files changed, 149 insertions(+), 133 deletions(-) diff --git a/Facepunch.Steamworks/SteamApps.cs b/Facepunch.Steamworks/SteamApps.cs index f599ffb..0319e15 100644 --- a/Facepunch.Steamworks/SteamApps.cs +++ b/Facepunch.Steamworks/SteamApps.cs @@ -11,16 +11,14 @@ namespace Steamworks /// /// Exposes a wide range of information and actions for applications and Downloadable Content (DLC). /// - public class SteamApps : SteamClass + public class SteamApps : SteamClass { - internal static ISteamApps Internal; - internal override SteamInterface Interface => Internal; + internal static ISteamApps Internal => Interface as ISteamApps; internal override void InitializeInterface( bool server ) { - Internal = new ISteamApps( server ); + SetInterface( server, new ISteamApps( server ) ); } - internal static void InstallEvents() { diff --git a/Facepunch.Steamworks/SteamClient.cs b/Facepunch.Steamworks/SteamClient.cs index d81cfb8..1d10164 100644 --- a/Facepunch.Steamworks/SteamClient.cs +++ b/Facepunch.Steamworks/SteamClient.cs @@ -79,7 +79,7 @@ namespace Steamworks { foreach ( var e in openInterfaces ) { - e.DestroyInterface(); + e.DestroyInterface( false ); } openInterfaces.Clear(); diff --git a/Facepunch.Steamworks/SteamFriends.cs b/Facepunch.Steamworks/SteamFriends.cs index f7d4a89..f4f9157 100644 --- a/Facepunch.Steamworks/SteamFriends.cs +++ b/Facepunch.Steamworks/SteamFriends.cs @@ -10,14 +10,13 @@ namespace Steamworks /// /// Undocumented Parental Settings /// - public class SteamFriends : SteamClass + public class SteamFriends : SteamClass { - internal static ISteamFriends Internal; - internal override SteamInterface Interface => Internal; + internal static ISteamFriends Internal => Interface as ISteamFriends; internal override void InitializeInterface( bool server ) { - Internal = new ISteamFriends( server ); + SetInterface( server, new ISteamFriends( server ) ); richPresence = new Dictionary(); } diff --git a/Facepunch.Steamworks/SteamInput.cs b/Facepunch.Steamworks/SteamInput.cs index 3663da7..03b8139 100644 --- a/Facepunch.Steamworks/SteamInput.cs +++ b/Facepunch.Steamworks/SteamInput.cs @@ -3,14 +3,13 @@ using System.Collections.Generic; namespace Steamworks { - public class SteamInput : SteamClass + public class SteamInput : SteamClass { - internal static ISteamInput Internal; - internal override SteamInterface Interface => Internal; + internal static ISteamInput Internal => Interface as ISteamInput; internal override void InitializeInterface( bool server ) { - Internal = new ISteamInput( server ); + SetInterface( server, new ISteamInput( server ) ); } internal const int STEAM_CONTROLLER_MAX_COUNT = 16; diff --git a/Facepunch.Steamworks/SteamInventory.cs b/Facepunch.Steamworks/SteamInventory.cs index ea89946..57c55f6 100644 --- a/Facepunch.Steamworks/SteamInventory.cs +++ b/Facepunch.Steamworks/SteamInventory.cs @@ -12,23 +12,28 @@ namespace Steamworks /// /// Undocumented Parental Settings /// - public class SteamInventory : SteamClass + public class SteamInventory : SteamClass { - internal static ISteamInventory Internal; - internal override SteamInterface Interface => Internal; + internal static ISteamInventory Internal => Interface as ISteamInventory; internal override void InitializeInterface( bool server ) { - Internal = new ISteamInventory( server ); + SetInterface( server, new ISteamInventory( server ) ); - InstallEvents(); + InstallEvents( server ); } - internal static void InstallEvents() + internal static void InstallEvents( bool server ) { - Dispatch.Install( x => InventoryUpdated( x ) ); - Dispatch.Install( x => LoadDefinitions() ); - Dispatch.Install( x => LoadDefinitions(), true ); + if ( !server ) + { + Dispatch.Install( x => InventoryUpdated( x ) ); + Dispatch.Install( x => LoadDefinitions() ); + } + else + { + Dispatch.Install( x => LoadDefinitions(), true ); + } } private static void InventoryUpdated( SteamInventoryFullUpdate_t x ) diff --git a/Facepunch.Steamworks/SteamMatchmaking.cs b/Facepunch.Steamworks/SteamMatchmaking.cs index 42354be..1264a2f 100644 --- a/Facepunch.Steamworks/SteamMatchmaking.cs +++ b/Facepunch.Steamworks/SteamMatchmaking.cs @@ -10,18 +10,16 @@ namespace Steamworks /// /// Functions for clients to access matchmaking services, favorites, and to operate on game lobbies /// - public class SteamMatchmaking : SteamClass + public class SteamMatchmaking : SteamClass { - internal static ISteamMatchmaking Internal; - internal override SteamInterface Interface => Internal; + internal static ISteamMatchmaking Internal => Interface as ISteamMatchmaking; internal override void InitializeInterface( bool server ) { - Internal = new ISteamMatchmaking( server ); + SetInterface( server, new ISteamMatchmaking( server ) ); InstallEvents(); } - /// /// Maximum number of characters a lobby metadata key can be diff --git a/Facepunch.Steamworks/SteamMatchmakingServers.cs b/Facepunch.Steamworks/SteamMatchmakingServers.cs index c748c29..8b9bd48 100644 --- a/Facepunch.Steamworks/SteamMatchmakingServers.cs +++ b/Facepunch.Steamworks/SteamMatchmakingServers.cs @@ -10,14 +10,13 @@ namespace Steamworks /// /// Functions for clients to access matchmaking services, favorites, and to operate on game lobbies /// - public class SteamMatchmakingServers : SteamClass + public class SteamMatchmakingServers : SteamClass { - internal static ISteamMatchmakingServers Internal; - internal override SteamInterface Interface => Internal; + internal static ISteamMatchmakingServers Internal => Interface as ISteamMatchmakingServers; internal override void InitializeInterface( bool server ) { - Internal = new ISteamMatchmakingServers( server ); + SetInterface( server, new ISteamMatchmakingServers( server ) ); } } } \ No newline at end of file diff --git a/Facepunch.Steamworks/SteamMusic.cs b/Facepunch.Steamworks/SteamMusic.cs index 5abafda..9095887 100644 --- a/Facepunch.Steamworks/SteamMusic.cs +++ b/Facepunch.Steamworks/SteamMusic.cs @@ -13,14 +13,13 @@ namespace Steamworks /// when an important cut scene is shown, and start playing afterwards. /// Nothing uses Steam Music though so this can probably get fucked /// - public class SteamMusic : SteamClass + public class SteamMusic : SteamClass { - internal static ISteamMusic Internal; - internal override SteamInterface Interface => Internal; + internal static ISteamMusic Internal => Interface as ISteamMusic; internal override void InitializeInterface( bool server ) { - Internal = new ISteamMusic( server ); + SetInterface( server, new ISteamMusic( server ) ); InstallEvents(); } diff --git a/Facepunch.Steamworks/SteamNetworking.cs b/Facepunch.Steamworks/SteamNetworking.cs index 95de3f6..ed1650a 100644 --- a/Facepunch.Steamworks/SteamNetworking.cs +++ b/Facepunch.Steamworks/SteamNetworking.cs @@ -8,22 +8,21 @@ using Steamworks.Data; namespace Steamworks { - public class SteamNetworking : SteamClass + public class SteamNetworking : SteamClass { - internal static ISteamNetworking Internal; - internal override SteamInterface Interface => Internal; + internal static ISteamNetworking Internal => Interface as ISteamNetworking; internal override void InitializeInterface( bool server ) { - Internal = new ISteamNetworking( server ); + SetInterface( server, new ISteamNetworking( server ) ); - InstallEvents(); + InstallEvents( server ); } - internal static void InstallEvents() + internal static void InstallEvents( bool server ) { - Dispatch.Install( x => OnP2PSessionRequest?.Invoke( x.SteamIDRemote ) ); - Dispatch.Install( x => OnP2PConnectionFailed?.Invoke( x.SteamIDRemote, (P2PSessionError) x.P2PSessionError ) ); + Dispatch.Install( x => OnP2PSessionRequest?.Invoke( x.SteamIDRemote ), server ); + Dispatch.Install( x => OnP2PConnectionFailed?.Invoke( x.SteamIDRemote, (P2PSessionError) x.P2PSessionError ), server ); } /// diff --git a/Facepunch.Steamworks/SteamNetworkingSockets.cs b/Facepunch.Steamworks/SteamNetworkingSockets.cs index ee08e16..f308328 100644 --- a/Facepunch.Steamworks/SteamNetworkingSockets.cs +++ b/Facepunch.Steamworks/SteamNetworkingSockets.cs @@ -8,21 +8,20 @@ using Steamworks.Data; namespace Steamworks { - public class SteamNetworkingSockets : SteamClass + public class SteamNetworkingSockets : SteamClass { - internal static ISteamNetworkingSockets Internal; - internal override SteamInterface Interface => Internal; + internal static ISteamNetworkingSockets Internal => Interface as ISteamNetworkingSockets; internal override void InitializeInterface( bool server ) { - Internal = new ISteamNetworkingSockets( server ); + SetInterface( server, new ISteamNetworkingSockets( server ) ); SocketInterfaces = new Dictionary(); ConnectionInterfaces = new Dictionary(); - InstallEvents(); + InstallEvents( server ); } - + #region SocketInterface static Dictionary SocketInterfaces; @@ -69,7 +68,7 @@ namespace Steamworks - internal static void InstallEvents( bool server = false ) + internal static void InstallEvents( bool server ) { Dispatch.Install( ConnectionStatusChanged, server ); } diff --git a/Facepunch.Steamworks/SteamNetworkingUtils.cs b/Facepunch.Steamworks/SteamNetworkingUtils.cs index 4321591..676e213 100644 --- a/Facepunch.Steamworks/SteamNetworkingUtils.cs +++ b/Facepunch.Steamworks/SteamNetworkingUtils.cs @@ -10,22 +10,22 @@ namespace Steamworks /// /// Undocumented Parental Settings /// - public class SteamNetworkingUtils : SteamClass + public class SteamNetworkingUtils : SteamClass { - internal static ISteamNetworkingUtils Internal; - internal override SteamInterface Interface => Internal; + internal static ISteamNetworkingUtils Internal => Interface as ISteamNetworkingUtils; internal override void InitializeInterface( bool server ) { - Internal = new ISteamNetworkingUtils( server ); + SetInterface( server, new ISteamNetworkingUtils( server ) ); + InstallCallbacks( server ); } - static void InstallCallbacks() + static void InstallCallbacks( bool server ) { Dispatch.Install( x => { Status = x.Avail; - } ); + }, server ); } public static SteamNetworkingAvailability Status { get; private set; } diff --git a/Facepunch.Steamworks/SteamParental.cs b/Facepunch.Steamworks/SteamParental.cs index c8eb44f..112879c 100644 --- a/Facepunch.Steamworks/SteamParental.cs +++ b/Facepunch.Steamworks/SteamParental.cs @@ -10,21 +10,19 @@ namespace Steamworks /// /// Undocumented Parental Settings /// - public class SteamParental : SteamClass + public class SteamParental : SteamClass { - internal static ISteamParentalSettings Internal; - internal override SteamInterface Interface => Internal; + internal static ISteamParentalSettings Internal => Interface as ISteamParentalSettings; internal override void InitializeInterface( bool server ) { - Internal = new ISteamParentalSettings( server ); - InstallEvents(); + SetInterface( server, new ISteamParentalSettings( server ) ); + InstallEvents( server ); } - - internal static void InstallEvents() + internal static void InstallEvents( bool server ) { - Dispatch.Install( x => OnSettingsChanged?.Invoke() ); + Dispatch.Install( x => OnSettingsChanged?.Invoke(), server ); } /// diff --git a/Facepunch.Steamworks/SteamParties.cs b/Facepunch.Steamworks/SteamParties.cs index acad359..17d2a49 100644 --- a/Facepunch.Steamworks/SteamParties.cs +++ b/Facepunch.Steamworks/SteamParties.cs @@ -7,21 +7,20 @@ using Steamworks.Data; namespace Steamworks { - public class SteamParties : SteamClass + public class SteamParties : SteamClass { - internal static ISteamParties Internal; - internal override SteamInterface Interface => Internal; + internal static ISteamParties Internal => Interface as ISteamParties; internal override void InitializeInterface( bool server ) { - Internal = new ISteamParties( server ); - InstallEvents(); + SetInterface( server, new ISteamParties( server ) ); + InstallEvents( server ); } - internal static void InstallEvents() + internal static void InstallEvents( bool server ) { - Dispatch.Install( x => OnBeaconLocationsUpdated?.Invoke() ); - Dispatch.Install( x => OnActiveBeaconsUpdated?.Invoke() ); + Dispatch.Install( x => OnBeaconLocationsUpdated?.Invoke(), server ); + Dispatch.Install( x => OnActiveBeaconsUpdated?.Invoke(), server ); } /// diff --git a/Facepunch.Steamworks/SteamRemoteStorage.cs b/Facepunch.Steamworks/SteamRemoteStorage.cs index fc3c6bf..f54c484 100644 --- a/Facepunch.Steamworks/SteamRemoteStorage.cs +++ b/Facepunch.Steamworks/SteamRemoteStorage.cs @@ -10,15 +10,15 @@ namespace Steamworks /// /// Undocumented Parental Settings /// - public class SteamRemoteStorage : SteamClass + public class SteamRemoteStorage : SteamClass { - internal static ISteamRemoteStorage Internal; - internal override SteamInterface Interface => Internal; + internal static ISteamRemoteStorage Internal => Interface as ISteamRemoteStorage; internal override void InitializeInterface( bool server ) { - Internal = new ISteamRemoteStorage( server ); + SetInterface( server, new ISteamRemoteStorage( server ) ); } + /// /// Creates a new file, writes the bytes to the file, and then closes the file. diff --git a/Facepunch.Steamworks/SteamScreenshots.cs b/Facepunch.Steamworks/SteamScreenshots.cs index f4d4eb3..41b9de8 100644 --- a/Facepunch.Steamworks/SteamScreenshots.cs +++ b/Facepunch.Steamworks/SteamScreenshots.cs @@ -10,14 +10,13 @@ namespace Steamworks /// /// Undocumented Parental Settings /// - public class SteamScreenshots : SteamClass + public class SteamScreenshots : SteamClass { - internal static ISteamScreenshots Internal; - internal override SteamInterface Interface => Internal; + internal static ISteamScreenshots Internal => Interface as ISteamScreenshots; internal override void InitializeInterface( bool server ) { - Internal = new ISteamScreenshots( server ); + SetInterface( server, new ISteamScreenshots( server ) ); InstallEvents(); } diff --git a/Facepunch.Steamworks/SteamServer.cs b/Facepunch.Steamworks/SteamServer.cs index 1249933..8ddae0a 100644 --- a/Facepunch.Steamworks/SteamServer.cs +++ b/Facepunch.Steamworks/SteamServer.cs @@ -10,14 +10,13 @@ namespace Steamworks /// /// Provides the core of the Steam Game Servers API /// - public partial class SteamServer : SteamClass + public partial class SteamServer : SteamClass { - internal static ISteamGameServer Internal; - internal override SteamInterface Interface => Internal; + internal static ISteamGameServer Internal => Interface as ISteamGameServer; internal override void InitializeInterface( bool server ) { - Internal = new ISteamGameServer( server ); + SetInterface( server, new ISteamGameServer( server ) ); InstallEvents(); } @@ -28,9 +27,6 @@ namespace Steamworks internal static void InstallEvents() { - SteamInventory.InstallEvents(); - //SteamNetworkingSockets.InstallEvents(true); - Dispatch.Install( x => OnValidateAuthTicketResponse?.Invoke( x.SteamID, x.OwnerSteamID, x.AuthSessionResponse ), true ); Dispatch.Install( x => OnSteamServersConnected?.Invoke(), true ); Dispatch.Install( x => OnSteamServerConnectFailure?.Invoke( x.Result, x.StillRetrying ), true ); @@ -141,7 +137,7 @@ namespace Steamworks { foreach ( var e in openInterfaces ) { - e.DestroyInterface(); + e.DestroyInterface( true ); } openInterfaces.Clear(); @@ -149,8 +145,6 @@ namespace Steamworks public static void Shutdown() { - Internal = null; - ShutdownInterfaces(); SteamGameServer.Shutdown(); } diff --git a/Facepunch.Steamworks/SteamServerStats.cs b/Facepunch.Steamworks/SteamServerStats.cs index 84b2b35..766c1f9 100644 --- a/Facepunch.Steamworks/SteamServerStats.cs +++ b/Facepunch.Steamworks/SteamServerStats.cs @@ -7,15 +7,15 @@ using Steamworks.Data; namespace Steamworks { - public class SteamServerStats : SteamClass + public class SteamServerStats : SteamClass { - internal static ISteamGameServerStats Internal; - internal override SteamInterface Interface => Internal; + internal static ISteamGameServerStats Internal => Interface as ISteamGameServerStats; internal override void InitializeInterface( bool server ) { - Internal = new ISteamGameServerStats( server ); + SetInterface( server, new ISteamGameServerStats( server ) ); } + /// /// Downloads stats for the user diff --git a/Facepunch.Steamworks/SteamUgc.cs b/Facepunch.Steamworks/SteamUgc.cs index b0b7029..db10f45 100644 --- a/Facepunch.Steamworks/SteamUgc.cs +++ b/Facepunch.Steamworks/SteamUgc.cs @@ -12,20 +12,19 @@ namespace Steamworks /// Functions for accessing and manipulating Steam user information. /// This is also where the APIs for Steam Voice are exposed. /// - public class SteamUGC : SteamClass + public class SteamUGC : SteamClass { - internal static ISteamUGC Internal; - internal override SteamInterface Interface => Internal; + internal static ISteamUGC Internal => Interface as ISteamUGC; internal override void InitializeInterface( bool server ) { - Internal = new ISteamUGC( server ); - InstallEvents(); + SetInterface( server, new ISteamUGC( server ) ); + InstallEvents( server ); } - internal static void InstallEvents() + internal static void InstallEvents( bool server ) { - Dispatch.Install( x => OnDownloadItemResult?.Invoke( x.Result ) ); + Dispatch.Install( x => OnDownloadItemResult?.Invoke( x.Result ), server ); } /// diff --git a/Facepunch.Steamworks/SteamUser.cs b/Facepunch.Steamworks/SteamUser.cs index 24e8a6a..a0d3a03 100644 --- a/Facepunch.Steamworks/SteamUser.cs +++ b/Facepunch.Steamworks/SteamUser.cs @@ -13,14 +13,13 @@ namespace Steamworks /// Functions for accessing and manipulating Steam user information. /// This is also where the APIs for Steam Voice are exposed. /// - public class SteamUser : SteamClass + public class SteamUser : SteamClass { - internal static ISteamUser Internal; - internal override SteamInterface Interface => Internal; + internal static ISteamUser Internal => Interface as ISteamUser; internal override void InitializeInterface( bool server ) { - Internal = new ISteamUser( server ); + SetInterface( server, new ISteamUser( server ) ); InstallEvents(); richPresence = new Dictionary(); diff --git a/Facepunch.Steamworks/SteamUserStats.cs b/Facepunch.Steamworks/SteamUserStats.cs index 5ec4f67..e2352d8 100644 --- a/Facepunch.Steamworks/SteamUserStats.cs +++ b/Facepunch.Steamworks/SteamUserStats.cs @@ -7,15 +7,13 @@ using Steamworks.Data; namespace Steamworks { - public class SteamUserStats : SteamClass + public class SteamUserStats : SteamClass { - internal static ISteamUserStats Internal; - internal override SteamInterface Interface => Internal; + internal static ISteamUserStats Internal => Interface as ISteamUserStats; internal override void InitializeInterface( bool server ) { - Internal = new ISteamUserStats( server ); - + SetInterface( server, new ISteamUserStats( server ) ); InstallEvents(); RequestCurrentStats(); } diff --git a/Facepunch.Steamworks/SteamUtils.cs b/Facepunch.Steamworks/SteamUtils.cs index e7faa8e..d28d79c 100644 --- a/Facepunch.Steamworks/SteamUtils.cs +++ b/Facepunch.Steamworks/SteamUtils.cs @@ -10,24 +10,22 @@ namespace Steamworks /// /// Interface which provides access to a range of miscellaneous utility functions /// - public class SteamUtils : SteamClass + public class SteamUtils : SteamClass { - internal static ISteamUtils Internal; - internal override SteamInterface Interface => Internal; + internal static ISteamUtils Internal => Interface as ISteamUtils; internal override void InitializeInterface( bool server ) { - Internal = new ISteamUtils( server ); - - InstallEvents(); + SetInterface( server, new ISteamUtils( server ) ); + InstallEvents( server ); } - internal static void InstallEvents() + internal static void InstallEvents( bool server ) { - Dispatch.Install( x => OnIpCountryChanged?.Invoke() ); - Dispatch.Install( x => OnLowBatteryPower?.Invoke( x.MinutesBatteryLeft ) ); - Dispatch.Install( x => SteamClosed() ); - Dispatch.Install( x => OnGamepadTextInputDismissed?.Invoke( x.Submitted ) ); + Dispatch.Install( x => OnIpCountryChanged?.Invoke(), server ); + Dispatch.Install( x => OnLowBatteryPower?.Invoke( x.MinutesBatteryLeft ), server ); + Dispatch.Install( x => SteamClosed(), server ); + Dispatch.Install( x => OnGamepadTextInputDismissed?.Invoke( x.Submitted ), server ); } private static void SteamClosed() diff --git a/Facepunch.Steamworks/SteamVideo.cs b/Facepunch.Steamworks/SteamVideo.cs index e5ef99c..37e9732 100644 --- a/Facepunch.Steamworks/SteamVideo.cs +++ b/Facepunch.Steamworks/SteamVideo.cs @@ -10,15 +10,13 @@ namespace Steamworks /// /// Undocumented Parental Settings /// - public class SteamVideo : SteamClass + public class SteamVideo : SteamClass { - internal static ISteamVideo Internal; - internal override SteamInterface Interface => Internal; + internal static ISteamVideo Internal => Interface as ISteamVideo; internal override void InitializeInterface( bool server ) { - Internal = new ISteamVideo( server ); - + SetInterface( server, new ISteamVideo( server ) ); InstallEvents(); } diff --git a/Facepunch.Steamworks/Utility/SteamInterface.cs b/Facepunch.Steamworks/Utility/SteamInterface.cs index f012ed8..10e1cb9 100644 --- a/Facepunch.Steamworks/Utility/SteamInterface.cs +++ b/Facepunch.Steamworks/Utility/SteamInterface.cs @@ -16,20 +16,33 @@ namespace Steamworks public virtual IntPtr GetGlobalInterfacePointer() => IntPtr.Zero; public IntPtr Self; + public IntPtr SelfGlobal; + public IntPtr SelfServer; + public IntPtr SelfClient; public bool IsValid => Self != IntPtr.Zero; internal void SetupInterface( bool gameServer ) { - Self = GetGlobalInterfacePointer(); + if ( Self != IntPtr.Zero ) + return; + + SelfGlobal = GetGlobalInterfacePointer(); + Self = SelfGlobal; if ( Self != IntPtr.Zero ) return; if ( gameServer ) - Self = GetServerInterfacePointer(); + { + SelfServer = GetServerInterfacePointer(); + Self = SelfServer; + } else - Self = GetUserInterfacePointer(); + { + SelfClient = GetUserInterfacePointer(); + Self = SelfClient; + } } internal void ShutdownInterface() @@ -41,12 +54,38 @@ namespace Steamworks public abstract class SteamClass { internal abstract void InitializeInterface( bool server ); - internal virtual void DestroyInterface() + internal abstract void DestroyInterface( bool server ); + } + + public class SteamClass : SteamClass + { + internal static SteamInterface Interface => InterfaceClient != null ? InterfaceClient : InterfaceServer; + internal static SteamInterface InterfaceClient; + internal static SteamInterface InterfaceServer; + + internal override void InitializeInterface( bool server ) { - Interface.ShutdownInterface(); + } - internal abstract SteamInterface Interface { get; } + internal virtual void SetInterface( bool server, SteamInterface iface ) + { + if ( server ) + { + InterfaceServer = iface; + } + + if ( !server ) + { + InterfaceClient = iface; + } + } + + internal override void DestroyInterface( bool server ) + { + InterfaceClient = null; + InterfaceServer = null; + } } } \ No newline at end of file