Prefer use client interface if both exist (this might need a big change at some point)

This commit is contained in:
Garry Newman 2020-02-23 11:25:56 +00:00
parent 8f36f0c939
commit bc9801c36a
23 changed files with 149 additions and 133 deletions

View File

@ -11,16 +11,14 @@ namespace Steamworks
/// <summary>
/// Exposes a wide range of information and actions for applications and Downloadable Content (DLC).
/// </summary>
public class SteamApps : SteamClass
public class SteamApps : SteamClass<SteamApps>
{
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()
{

View File

@ -79,7 +79,7 @@ namespace Steamworks
{
foreach ( var e in openInterfaces )
{
e.DestroyInterface();
e.DestroyInterface( false );
}
openInterfaces.Clear();

View File

@ -10,14 +10,13 @@ namespace Steamworks
/// <summary>
/// Undocumented Parental Settings
/// </summary>
public class SteamFriends : SteamClass
public class SteamFriends : SteamClass<SteamFriends>
{
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<string, string>();
}

View File

@ -3,14 +3,13 @@ using System.Collections.Generic;
namespace Steamworks
{
public class SteamInput : SteamClass
public class SteamInput : SteamClass<SteamInput>
{
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;

View File

@ -12,23 +12,28 @@ namespace Steamworks
/// <summary>
/// Undocumented Parental Settings
/// </summary>
public class SteamInventory : SteamClass
public class SteamInventory : SteamClass<SteamInventory>
{
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<SteamInventoryFullUpdate_t>( x => InventoryUpdated( x ) );
Dispatch.Install<SteamInventoryDefinitionUpdate_t>( x => LoadDefinitions() );
Dispatch.Install<SteamInventoryDefinitionUpdate_t>( x => LoadDefinitions(), true );
if ( !server )
{
Dispatch.Install<SteamInventoryFullUpdate_t>( x => InventoryUpdated( x ) );
Dispatch.Install<SteamInventoryDefinitionUpdate_t>( x => LoadDefinitions() );
}
else
{
Dispatch.Install<SteamInventoryDefinitionUpdate_t>( x => LoadDefinitions(), true );
}
}
private static void InventoryUpdated( SteamInventoryFullUpdate_t x )

View File

@ -10,18 +10,16 @@ namespace Steamworks
/// <summary>
/// Functions for clients to access matchmaking services, favorites, and to operate on game lobbies
/// </summary>
public class SteamMatchmaking : SteamClass
public class SteamMatchmaking : SteamClass<SteamMatchmaking>
{
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();
}
/// <summary>
/// Maximum number of characters a lobby metadata key can be

View File

@ -10,14 +10,13 @@ namespace Steamworks
/// <summary>
/// Functions for clients to access matchmaking services, favorites, and to operate on game lobbies
/// </summary>
public class SteamMatchmakingServers : SteamClass
public class SteamMatchmakingServers : SteamClass<SteamMatchmakingServers>
{
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 ) );
}
}
}

View File

@ -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
/// </summary>
public class SteamMusic : SteamClass
public class SteamMusic : SteamClass<SteamMusic>
{
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();
}

View File

@ -8,22 +8,21 @@ using Steamworks.Data;
namespace Steamworks
{
public class SteamNetworking : SteamClass
public class SteamNetworking : SteamClass<SteamNetworking>
{
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<P2PSessionRequest_t>( x => OnP2PSessionRequest?.Invoke( x.SteamIDRemote ) );
Dispatch.Install<P2PSessionConnectFail_t>( x => OnP2PConnectionFailed?.Invoke( x.SteamIDRemote, (P2PSessionError) x.P2PSessionError ) );
Dispatch.Install<P2PSessionRequest_t>( x => OnP2PSessionRequest?.Invoke( x.SteamIDRemote ), server );
Dispatch.Install<P2PSessionConnectFail_t>( x => OnP2PConnectionFailed?.Invoke( x.SteamIDRemote, (P2PSessionError) x.P2PSessionError ), server );
}
/// <summary>

View File

@ -8,21 +8,20 @@ using Steamworks.Data;
namespace Steamworks
{
public class SteamNetworkingSockets : SteamClass
public class SteamNetworkingSockets : SteamClass<SteamNetworkingSockets>
{
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<uint, SocketInterface>();
ConnectionInterfaces = new Dictionary<uint, ConnectionInterface>();
InstallEvents();
InstallEvents( server );
}
#region SocketInterface
static Dictionary<uint, SocketInterface> SocketInterfaces;
@ -69,7 +68,7 @@ namespace Steamworks
internal static void InstallEvents( bool server = false )
internal static void InstallEvents( bool server )
{
Dispatch.Install<SteamNetConnectionStatusChangedCallback_t>( ConnectionStatusChanged, server );
}

View File

@ -10,22 +10,22 @@ namespace Steamworks
/// <summary>
/// Undocumented Parental Settings
/// </summary>
public class SteamNetworkingUtils : SteamClass
public class SteamNetworkingUtils : SteamClass<SteamNetworkingUtils>
{
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<SteamRelayNetworkStatus_t>( x =>
{
Status = x.Avail;
} );
}, server );
}
public static SteamNetworkingAvailability Status { get; private set; }

View File

@ -10,21 +10,19 @@ namespace Steamworks
/// <summary>
/// Undocumented Parental Settings
/// </summary>
public class SteamParental : SteamClass
public class SteamParental : SteamClass<SteamParental>
{
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<SteamParentalSettingsChanged_t>( x => OnSettingsChanged?.Invoke() );
Dispatch.Install<SteamParentalSettingsChanged_t>( x => OnSettingsChanged?.Invoke(), server );
}
/// <summary>

View File

@ -7,21 +7,20 @@ using Steamworks.Data;
namespace Steamworks
{
public class SteamParties : SteamClass
public class SteamParties : SteamClass<SteamParties>
{
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<AvailableBeaconLocationsUpdated_t>( x => OnBeaconLocationsUpdated?.Invoke() );
Dispatch.Install<ActiveBeaconsUpdated_t>( x => OnActiveBeaconsUpdated?.Invoke() );
Dispatch.Install<AvailableBeaconLocationsUpdated_t>( x => OnBeaconLocationsUpdated?.Invoke(), server );
Dispatch.Install<ActiveBeaconsUpdated_t>( x => OnActiveBeaconsUpdated?.Invoke(), server );
}
/// <summary>

View File

@ -10,15 +10,15 @@ namespace Steamworks
/// <summary>
/// Undocumented Parental Settings
/// </summary>
public class SteamRemoteStorage : SteamClass
public class SteamRemoteStorage : SteamClass<SteamRemoteStorage>
{
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 ) );
}
/// <summary>
/// Creates a new file, writes the bytes to the file, and then closes the file.

View File

@ -10,14 +10,13 @@ namespace Steamworks
/// <summary>
/// Undocumented Parental Settings
/// </summary>
public class SteamScreenshots : SteamClass
public class SteamScreenshots : SteamClass<SteamScreenshots>
{
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();
}

View File

@ -10,14 +10,13 @@ namespace Steamworks
/// <summary>
/// Provides the core of the Steam Game Servers API
/// </summary>
public partial class SteamServer : SteamClass
public partial class SteamServer : SteamClass<SteamServer>
{
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<ValidateAuthTicketResponse_t>( x => OnValidateAuthTicketResponse?.Invoke( x.SteamID, x.OwnerSteamID, x.AuthSessionResponse ), true );
Dispatch.Install<SteamServersConnected_t>( x => OnSteamServersConnected?.Invoke(), true );
Dispatch.Install<SteamServerConnectFailure_t>( 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();
}

View File

@ -7,15 +7,15 @@ using Steamworks.Data;
namespace Steamworks
{
public class SteamServerStats : SteamClass
public class SteamServerStats : SteamClass<SteamServerStats>
{
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 ) );
}
/// <summary>
/// Downloads stats for the user

View File

@ -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.
/// </summary>
public class SteamUGC : SteamClass
public class SteamUGC : SteamClass<SteamUGC>
{
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<DownloadItemResult_t>( x => OnDownloadItemResult?.Invoke( x.Result ) );
Dispatch.Install<DownloadItemResult_t>( x => OnDownloadItemResult?.Invoke( x.Result ), server );
}
/// <summary>

View File

@ -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.
/// </summary>
public class SteamUser : SteamClass
public class SteamUser : SteamClass<SteamUser>
{
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<string, string>();

View File

@ -7,15 +7,13 @@ using Steamworks.Data;
namespace Steamworks
{
public class SteamUserStats : SteamClass
public class SteamUserStats : SteamClass<SteamUserStats>
{
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();
}

View File

@ -10,24 +10,22 @@ namespace Steamworks
/// <summary>
/// Interface which provides access to a range of miscellaneous utility functions
/// </summary>
public class SteamUtils : SteamClass
public class SteamUtils : SteamClass<SteamUtils>
{
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<IPCountry_t>( x => OnIpCountryChanged?.Invoke() );
Dispatch.Install<LowBatteryPower_t>( x => OnLowBatteryPower?.Invoke( x.MinutesBatteryLeft ) );
Dispatch.Install<SteamShutdown_t>( x => SteamClosed() );
Dispatch.Install<GamepadTextInputDismissed_t>( x => OnGamepadTextInputDismissed?.Invoke( x.Submitted ) );
Dispatch.Install<IPCountry_t>( x => OnIpCountryChanged?.Invoke(), server );
Dispatch.Install<LowBatteryPower_t>( x => OnLowBatteryPower?.Invoke( x.MinutesBatteryLeft ), server );
Dispatch.Install<SteamShutdown_t>( x => SteamClosed(), server );
Dispatch.Install<GamepadTextInputDismissed_t>( x => OnGamepadTextInputDismissed?.Invoke( x.Submitted ), server );
}
private static void SteamClosed()

View File

@ -10,15 +10,13 @@ namespace Steamworks
/// <summary>
/// Undocumented Parental Settings
/// </summary>
public class SteamVideo : SteamClass
public class SteamVideo : SteamClass<SteamVideo>
{
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();
}

View File

@ -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<T> : 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;
}
}
}