New initialization methods

This commit is contained in:
Garry Newman 2020-02-10 20:22:17 +00:00
parent 12f95a7f4e
commit fa69dbda01
45 changed files with 284 additions and 695 deletions

View File

@ -9,14 +9,7 @@ namespace Steamworks
{ {
internal class ISteamApps : SteamInterface internal class ISteamApps : SteamInterface
{ {
public override void InitInternals() public override IntPtr GetInterfacePointer() => GetApi.SteamApps();
{
}
internal override void Shutdown()
{
base.Shutdown();
}
#region FunctionMeta #region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamApps_BIsSubscribed")] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamApps_BIsSubscribed")]

View File

@ -9,14 +9,7 @@ namespace Steamworks
{ {
internal class ISteamFriends : SteamInterface internal class ISteamFriends : SteamInterface
{ {
public override void InitInternals() public override IntPtr GetInterfacePointer() => GetApi.SteamFriends();
{
}
internal override void Shutdown()
{
base.Shutdown();
}
#region FunctionMeta #region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamFriends_GetPersonaName")] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamFriends_GetPersonaName")]

View File

@ -9,14 +9,7 @@ namespace Steamworks
{ {
internal class ISteamGameServer : SteamInterface internal class ISteamGameServer : SteamInterface
{ {
public override void InitInternals() public override IntPtr GetInterfacePointer() => GetApi.SteamGameServer();
{
}
internal override void Shutdown()
{
base.Shutdown();
}
#region FunctionMeta #region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamGameServer_InitGameServer")] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamGameServer_InitGameServer")]

View File

@ -9,14 +9,7 @@ namespace Steamworks
{ {
internal class ISteamGameServerStats : SteamInterface internal class ISteamGameServerStats : SteamInterface
{ {
public override void InitInternals() public override IntPtr GetInterfacePointer() => GetApi.SteamGameServerStats();
{
}
internal override void Shutdown()
{
base.Shutdown();
}
#region FunctionMeta #region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamGameServerStats_RequestUserStats")] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamGameServerStats_RequestUserStats")]

View File

@ -9,14 +9,7 @@ namespace Steamworks
{ {
internal class ISteamInput : SteamInterface internal class ISteamInput : SteamInterface
{ {
public override void InitInternals() public override IntPtr GetInterfacePointer() => GetApi.SteamInput();
{
}
internal override void Shutdown()
{
base.Shutdown();
}
#region FunctionMeta #region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamInput_Init")] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamInput_Init")]

View File

@ -9,14 +9,7 @@ namespace Steamworks
{ {
internal class ISteamInventory : SteamInterface internal class ISteamInventory : SteamInterface
{ {
public override void InitInternals() public override IntPtr GetInterfacePointer() => GetApi.SteamInventory();
{
}
internal override void Shutdown()
{
base.Shutdown();
}
#region FunctionMeta #region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamInventory_GetResultStatus")] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamInventory_GetResultStatus")]

View File

@ -9,14 +9,7 @@ namespace Steamworks
{ {
internal class ISteamMatchmaking : SteamInterface internal class ISteamMatchmaking : SteamInterface
{ {
public override void InitInternals() public override IntPtr GetInterfacePointer() => GetApi.SteamMatchmaking();
{
}
internal override void Shutdown()
{
base.Shutdown();
}
#region FunctionMeta #region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamMatchmaking_GetFavoriteGameCount")] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamMatchmaking_GetFavoriteGameCount")]

View File

@ -9,14 +9,7 @@ namespace Steamworks
{ {
internal class ISteamMatchmakingServers : SteamInterface internal class ISteamMatchmakingServers : SteamInterface
{ {
public override void InitInternals() public override IntPtr GetInterfacePointer() => GetApi.SteamMatchmakingServers();
{
}
internal override void Shutdown()
{
base.Shutdown();
}
#region FunctionMeta #region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamMatchmakingServers_RequestInternetServerList")] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamMatchmakingServers_RequestInternetServerList")]

View File

@ -9,14 +9,7 @@ namespace Steamworks
{ {
internal class ISteamMusic : SteamInterface internal class ISteamMusic : SteamInterface
{ {
public override void InitInternals() public override IntPtr GetInterfacePointer() => GetApi.SteamMusic();
{
}
internal override void Shutdown()
{
base.Shutdown();
}
#region FunctionMeta #region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamMusic_BIsEnabled")] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamMusic_BIsEnabled")]

View File

@ -9,14 +9,7 @@ namespace Steamworks
{ {
internal class ISteamNetworking : SteamInterface internal class ISteamNetworking : SteamInterface
{ {
public override void InitInternals() public override IntPtr GetInterfacePointer() => GetApi.SteamNetworking();
{
}
internal override void Shutdown()
{
base.Shutdown();
}
#region FunctionMeta #region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamNetworking_SendP2PPacket")] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamNetworking_SendP2PPacket")]

View File

@ -9,14 +9,7 @@ namespace Steamworks
{ {
internal class ISteamNetworkingSockets : SteamInterface internal class ISteamNetworkingSockets : SteamInterface
{ {
public override void InitInternals() public override IntPtr GetInterfacePointer() => GetApi.SteamNetworkingSockets();
{
}
internal override void Shutdown()
{
base.Shutdown();
}
} }
} }

View File

@ -9,14 +9,7 @@ namespace Steamworks
{ {
internal class ISteamNetworkingUtils : SteamInterface internal class ISteamNetworkingUtils : SteamInterface
{ {
public override void InitInternals() public override IntPtr GetInterfacePointer() => GetApi.SteamNetworkingUtils();
{
}
internal override void Shutdown()
{
base.Shutdown();
}
} }
} }

View File

@ -9,14 +9,7 @@ namespace Steamworks
{ {
internal class ISteamParentalSettings : SteamInterface internal class ISteamParentalSettings : SteamInterface
{ {
public override void InitInternals() public override IntPtr GetInterfacePointer() => GetApi.SteamParentalSettings();
{
}
internal override void Shutdown()
{
base.Shutdown();
}
#region FunctionMeta #region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamParentalSettings_BIsParentalLockEnabled")] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamParentalSettings_BIsParentalLockEnabled")]

View File

@ -9,14 +9,7 @@ namespace Steamworks
{ {
internal class ISteamParties : SteamInterface internal class ISteamParties : SteamInterface
{ {
public override void InitInternals() public override IntPtr GetInterfacePointer() => GetApi.SteamParties();
{
}
internal override void Shutdown()
{
base.Shutdown();
}
#region FunctionMeta #region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamParties_GetNumActiveBeacons")] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamParties_GetNumActiveBeacons")]

View File

@ -9,14 +9,7 @@ namespace Steamworks
{ {
internal class ISteamRemoteStorage : SteamInterface internal class ISteamRemoteStorage : SteamInterface
{ {
public override void InitInternals() public override IntPtr GetInterfacePointer() => GetApi.SteamRemoteStorage();
{
}
internal override void Shutdown()
{
base.Shutdown();
}
#region FunctionMeta #region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamRemoteStorage_FileWrite")] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamRemoteStorage_FileWrite")]

View File

@ -9,14 +9,7 @@ namespace Steamworks
{ {
internal class ISteamScreenshots : SteamInterface internal class ISteamScreenshots : SteamInterface
{ {
public override void InitInternals() public override IntPtr GetInterfacePointer() => GetApi.SteamScreenshots();
{
}
internal override void Shutdown()
{
base.Shutdown();
}
#region FunctionMeta #region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamScreenshots_WriteScreenshot")] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamScreenshots_WriteScreenshot")]

View File

@ -9,14 +9,7 @@ namespace Steamworks
{ {
internal class ISteamUGC : SteamInterface internal class ISteamUGC : SteamInterface
{ {
public override void InitInternals() public override IntPtr GetInterfacePointer() => GetApi.SteamUGC();
{
}
internal override void Shutdown()
{
base.Shutdown();
}
#region FunctionMeta #region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamUGC_CreateQueryUserUGCRequest")] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamUGC_CreateQueryUserUGCRequest")]

View File

@ -9,14 +9,7 @@ namespace Steamworks
{ {
internal class ISteamUser : SteamInterface internal class ISteamUser : SteamInterface
{ {
public override void InitInternals() public override IntPtr GetInterfacePointer() => GetApi.SteamUser();
{
}
internal override void Shutdown()
{
base.Shutdown();
}
#region FunctionMeta #region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamUser_GetHSteamUser")] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamUser_GetHSteamUser")]

View File

@ -9,14 +9,7 @@ namespace Steamworks
{ {
internal class ISteamUserStats : SteamInterface internal class ISteamUserStats : SteamInterface
{ {
public override void InitInternals() public override IntPtr GetInterfacePointer() => GetApi.SteamUserStats();
{
}
internal override void Shutdown()
{
base.Shutdown();
}
#region FunctionMeta #region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamUserStats_RequestCurrentStats")] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamUserStats_RequestCurrentStats")]

View File

@ -9,14 +9,7 @@ namespace Steamworks
{ {
internal class ISteamUtils : SteamInterface internal class ISteamUtils : SteamInterface
{ {
public override void InitInternals() public override IntPtr GetInterfacePointer() => GetApi.SteamUtils();
{
}
internal override void Shutdown()
{
base.Shutdown();
}
#region FunctionMeta #region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamUtils_GetSecondsSinceAppActive")] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamUtils_GetSecondsSinceAppActive")]

View File

@ -9,14 +9,7 @@ namespace Steamworks
{ {
internal class ISteamVideo : SteamInterface internal class ISteamVideo : SteamInterface
{ {
public override void InitInternals() public override IntPtr GetInterfacePointer() => GetApi.SteamVideo();
{
}
internal override void Shutdown()
{
base.Shutdown();
}
#region FunctionMeta #region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamVideo_GetVideoURL")] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamVideo_GetVideoURL")]

View File

@ -11,27 +11,16 @@ namespace Steamworks
/// <summary> /// <summary>
/// Exposes a wide range of information and actions for applications and Downloadable Content (DLC). /// Exposes a wide range of information and actions for applications and Downloadable Content (DLC).
/// </summary> /// </summary>
public static class SteamApps public class SteamApps : SteamClass
{ {
static ISteamApps _internal; internal static ISteamApps Internal;
internal static ISteamApps Internal internal override SteamInterface Interface => Internal;
internal override void InitializeInterface()
{ {
get Internal = new ISteamApps();
{
if ( _internal == null )
{
_internal = new ISteamApps();
_internal.Init();
} }
return _internal;
}
}
internal static void Shutdown()
{
_internal = null;
}
internal static void InstallEvents() internal static void InstallEvents()
{ {

View File

@ -29,22 +29,24 @@ namespace Steamworks
initialized = true; initialized = true;
SteamApps.InstallEvents(); AddInterface<SteamApps>();
SteamUtils.InstallEvents(); AddInterface<SteamFriends>();
SteamParental.InstallEvents(); AddInterface<SteamInput>();
SteamMusic.InstallEvents(); AddInterface<SteamInventory>();
SteamVideo.InstallEvents(); AddInterface<SteamMatchmaking>();
SteamUser.InstallEvents(); AddInterface<SteamMusic>();
SteamFriends.InstallEvents(); AddInterface<SteamNetworking>();
SteamScreenshots.InstallEvents(); AddInterface<SteamNetworkingSockets>();
SteamUserStats.InstallEvents(); AddInterface<SteamNetworkingUtils>();
SteamInventory.InstallEvents(); AddInterface<SteamParental>();
SteamNetworking.InstallEvents(); AddInterface<SteamParties>();
SteamMatchmaking.InstallEvents(); AddInterface<SteamRemoteStorage>();
SteamParties.InstallEvents(); AddInterface<SteamScreenshots>();
SteamNetworkingSockets.InstallEvents(); AddInterface<SteamUGC>();
SteamInput.InstallEvents(); AddInterface<SteamUser>();
SteamUGC.InstallEvents(); AddInterface<SteamUserStats>();
AddInterface<SteamUtils>();
AddInterface<SteamVideo>();
if ( asyncCallbacks ) if ( asyncCallbacks )
{ {
@ -52,24 +54,29 @@ namespace Steamworks
} }
} }
static List<SteamInterface> openIterfaces = new List<SteamInterface>(); internal static void AddInterface<T>() where T : SteamClass, new()
{
var t = new T();
}
static List<SteamInterface> openInterfaces = new List<SteamInterface>();
internal static void WatchInterface( SteamInterface steamInterface ) internal static void WatchInterface( SteamInterface steamInterface )
{ {
if ( openIterfaces.Contains( steamInterface ) ) if ( openInterfaces.Contains( steamInterface ) )
throw new System.Exception( "openIterfaces already contains interface!" ); throw new System.Exception( "openIterfaces already contains interface!" );
openIterfaces.Add( steamInterface ); openInterfaces.Add( steamInterface );
} }
internal static void ShutdownInterfaces() internal static void ShutdownInterfaces()
{ {
foreach ( var e in openIterfaces ) foreach ( var e in openInterfaces )
{ {
e.Shutdown(); e.ShutdownInterface();
} }
openIterfaces.Clear(); openInterfaces.Clear();
} }
public static Action<Exception> OnCallbackException; public static Action<Exception> OnCallbackException;
@ -97,8 +104,6 @@ namespace Steamworks
{ {
if ( !IsValid ) return; if ( !IsValid ) return;
SteamInput.Shutdown();
Cleanup(); Cleanup();
SteamAPI.Shutdown(); SteamAPI.Shutdown();
@ -111,22 +116,6 @@ namespace Steamworks
Event.DisposeAllClient(); Event.DisposeAllClient();
ShutdownInterfaces(); ShutdownInterfaces();
SteamInput.Shutdown();
SteamApps.Shutdown();
SteamUtils.Shutdown();
SteamParental.Shutdown();
SteamMusic.Shutdown();
SteamVideo.Shutdown();
SteamUser.Shutdown();
SteamFriends.Shutdown();
SteamScreenshots.Shutdown();
SteamUserStats.Shutdown();
SteamInventory.Shutdown();
SteamNetworking.Shutdown();
SteamMatchmaking.Shutdown();
SteamParties.Shutdown();
SteamNetworkingUtils.Shutdown();
SteamNetworkingSockets.Shutdown();
ServerList.Base.Shutdown(); ServerList.Base.Shutdown();
} }

View File

@ -10,31 +10,18 @@ namespace Steamworks
/// <summary> /// <summary>
/// Undocumented Parental Settings /// Undocumented Parental Settings
/// </summary> /// </summary>
public static class SteamFriends public class SteamFriends : SteamClass
{ {
static ISteamFriends _internal; internal static ISteamFriends Internal;
internal static ISteamFriends Internal internal override SteamInterface Interface => Internal;
{
get
{
SteamClient.ValidCheck();
if ( _internal == null ) internal override void InitializeInterface()
{ {
_internal = new ISteamFriends(); Internal = new ISteamFriends();
_internal.Init();
richPresence = new Dictionary<string, string>(); richPresence = new Dictionary<string, string>();
} }
return _internal;
}
}
internal static void Shutdown()
{
_internal = null;
}
static Dictionary<string, string> richPresence; static Dictionary<string, string> richPresence;
internal static void InstallEvents() internal static void InstallEvents()

View File

@ -3,44 +3,18 @@ using System.Collections.Generic;
namespace Steamworks namespace Steamworks
{ {
public static class SteamInput public class SteamInput : SteamClass
{ {
internal static ISteamInput Internal;
internal override SteamInterface Interface => Internal;
internal override void InitializeInterface()
{
Internal = new ISteamInput();
}
internal const int STEAM_CONTROLLER_MAX_COUNT = 16; internal const int STEAM_CONTROLLER_MAX_COUNT = 16;
static ISteamInput _internal;
internal static ISteamInput Internal
{
get
{
SteamClient.ValidCheck();
if ( _internal == null )
{
_internal = new ISteamInput();
_internal.Init();
}
return _internal;
}
}
internal static void Shutdown()
{
if ( _internal != null && _internal.IsValid )
{
_internal.Shutdown();
}
_internal = null;
}
internal static void InstallEvents()
{
Internal.Init();
Internal.RunFrame();
// None?
}
/// <summary> /// <summary>
/// You shouldn't really need to call this because it get called by RunCallbacks on SteamClient /// You shouldn't really need to call this because it get called by RunCallbacks on SteamClient

View File

@ -12,25 +12,16 @@ namespace Steamworks
/// <summary> /// <summary>
/// Undocumented Parental Settings /// Undocumented Parental Settings
/// </summary> /// </summary>
public static class SteamInventory public class SteamInventory : SteamClass
{ {
static ISteamInventory _internal; internal static ISteamInventory Internal;
internal static ISteamInventory Internal internal override SteamInterface Interface => Internal;
{
get
{
if ( _internal == null )
{
_internal = new ISteamInventory();
_internal.Init();
}
return _internal; internal override void InitializeInterface()
}
}
internal static void Shutdown()
{ {
_internal = null; Internal = new ISteamInventory();
InstallEvents();
} }
internal static void InstallEvents() internal static void InstallEvents()

View File

@ -10,37 +10,25 @@ namespace Steamworks
/// <summary> /// <summary>
/// Functions for clients to access matchmaking services, favorites, and to operate on game lobbies /// Functions for clients to access matchmaking services, favorites, and to operate on game lobbies
/// </summary> /// </summary>
public static class SteamMatchmaking public class SteamMatchmaking : SteamClass
{ {
internal static ISteamMatchmaking Internal;
internal override SteamInterface Interface => Internal;
internal override void InitializeInterface()
{
Internal = new ISteamMatchmaking();
InstallEvents();
}
/// <summary> /// <summary>
/// Maximum number of characters a lobby metadata key can be /// Maximum number of characters a lobby metadata key can be
/// </summary> /// </summary>
internal static int MaxLobbyKeyLength => 255; internal static int MaxLobbyKeyLength => 255;
static ISteamMatchmaking _internal;
internal static ISteamMatchmaking Internal
{
get
{
SteamClient.ValidCheck();
if ( _internal == null )
{
_internal = new ISteamMatchmaking();
_internal.Init();
}
return _internal;
}
}
internal static void Shutdown()
{
_internal = null;
}
internal static void InstallEvents() internal static void InstallEvents()
{ {
LobbyInvite_t.Install( x => OnLobbyInvite?.Invoke( new Friend( x.SteamIDUser ), new Lobby( x.SteamIDLobby ) ) ); LobbyInvite_t.Install( x => OnLobbyInvite?.Invoke( new Friend( x.SteamIDUser ), new Lobby( x.SteamIDLobby ) ) );

View File

@ -13,27 +13,16 @@ namespace Steamworks
/// when an important cut scene is shown, and start playing afterwards. /// when an important cut scene is shown, and start playing afterwards.
/// Nothing uses Steam Music though so this can probably get fucked /// Nothing uses Steam Music though so this can probably get fucked
/// </summary> /// </summary>
public static class SteamMusic public class SteamMusic : SteamClass
{ {
static ISteamMusic _internal; internal static ISteamMusic Internal;
internal static ISteamMusic Internal internal override SteamInterface Interface => Internal;
{
get
{
SteamClient.ValidCheck();
if ( _internal == null ) internal override void InitializeInterface()
{ {
_internal = new ISteamMusic(); Internal = new ISteamMusic();
_internal.Init();
}
return _internal; InstallEvents();
}
}
internal static void Shutdown()
{
_internal = null;
} }
internal static void InstallEvents() internal static void InstallEvents()

View File

@ -8,26 +8,16 @@ using Steamworks.Data;
namespace Steamworks namespace Steamworks
{ {
public static class SteamNetworking public class SteamNetworking : SteamClass
{ {
static ISteamNetworking _internal; internal static ISteamNetworking Internal;
internal static ISteamNetworking Internal internal override SteamInterface Interface => Internal;
{
get
{
if ( _internal == null )
{
_internal = new ISteamNetworking();
_internal.Init();
}
return _internal; internal override void InitializeInterface()
}
}
internal static void Shutdown()
{ {
_internal = null; Internal = new ISteamNetworking();
InstallEvents();
} }
internal static void InstallEvents() internal static void InstallEvents()

View File

@ -8,24 +8,19 @@ using Steamworks.Data;
namespace Steamworks namespace Steamworks
{ {
public static class SteamNetworkingSockets public class SteamNetworkingSockets : SteamClass
{ {
static ISteamNetworkingSockets _internal; internal static ISteamNetworkingSockets Internal;
internal static ISteamNetworkingSockets Internal internal override SteamInterface Interface => Internal;
internal override void InitializeInterface()
{ {
get Internal = new ISteamNetworkingSockets();
{
if ( _internal == null )
{
_internal = new ISteamNetworkingSockets();
_internal.Init();
SocketInterfaces = new Dictionary<uint, SocketInterface>(); SocketInterfaces = new Dictionary<uint, SocketInterface>();
ConnectionInterfaces = new Dictionary<uint, ConnectionInterface>(); ConnectionInterfaces = new Dictionary<uint, ConnectionInterface>();
}
return _internal; InstallEvents();
}
} }
#region SocketInterface #region SocketInterface
@ -74,13 +69,6 @@ namespace Steamworks
} }
#endregion #endregion
internal static void Shutdown()
{
_internal = null;
SocketInterfaces = null;
ConnectionInterfaces = null;
}
internal static void InstallEvents( bool server = false ) internal static void InstallEvents( bool server = false )
{ {
SteamNetConnectionStatusChangedCallback_t.Install( x => ConnectionStatusChanged( x ), server ); SteamNetConnectionStatusChangedCallback_t.Install( x => ConnectionStatusChanged( x ), server );

View File

@ -10,26 +10,14 @@ namespace Steamworks
/// <summary> /// <summary>
/// Undocumented Parental Settings /// Undocumented Parental Settings
/// </summary> /// </summary>
public static class SteamNetworkingUtils public class SteamNetworkingUtils : SteamClass
{ {
static ISteamNetworkingUtils _internal; internal static ISteamNetworkingUtils Internal;
internal static ISteamNetworkingUtils Internal internal override SteamInterface Interface => Internal;
{
get
{
if ( _internal == null )
{
_internal = new ISteamNetworkingUtils();
_internal.InitUserless();
}
return _internal; internal override void InitializeInterface()
}
}
internal static void Shutdown()
{ {
_internal = null; Internal = new ISteamNetworkingUtils();
} }
/// <summary> /// <summary>

View File

@ -10,28 +10,17 @@ namespace Steamworks
/// <summary> /// <summary>
/// Undocumented Parental Settings /// Undocumented Parental Settings
/// </summary> /// </summary>
public static class SteamParental public class SteamParental : SteamClass
{ {
static ISteamParentalSettings _internal; internal static ISteamParentalSettings Internal;
internal static ISteamParentalSettings Internal internal override SteamInterface Interface => Internal;
{
get
{
SteamClient.ValidCheck();
if ( _internal == null ) internal override void InitializeInterface()
{ {
_internal = new ISteamParentalSettings(); Internal = new ISteamParentalSettings();
_internal.Init(); InstallEvents();
} }
return _internal;
}
}
internal static void Shutdown()
{
_internal = null;
}
internal static void InstallEvents() internal static void InstallEvents()
{ {

View File

@ -7,25 +7,15 @@ using Steamworks.Data;
namespace Steamworks namespace Steamworks
{ {
public static class SteamParties public class SteamParties : SteamClass
{ {
static ISteamParties _internal; internal static ISteamParties Internal;
internal static ISteamParties Internal internal override SteamInterface Interface => Internal;
{
get
{
if ( _internal == null )
{
_internal = new ISteamParties();
_internal.Init();
}
return _internal; internal override void InitializeInterface()
}
}
internal static void Shutdown()
{ {
_internal = null; Internal = new ISteamParties();
InstallEvents();
} }
internal static void InstallEvents() internal static void InstallEvents()

View File

@ -10,26 +10,14 @@ namespace Steamworks
/// <summary> /// <summary>
/// Undocumented Parental Settings /// Undocumented Parental Settings
/// </summary> /// </summary>
public static class SteamRemoteStorage public class SteamRemoteStorage : SteamClass
{ {
static ISteamRemoteStorage _internal; internal static ISteamRemoteStorage Internal;
internal static ISteamRemoteStorage Internal internal override SteamInterface Interface => Internal;
{
get
{
if ( _internal == null )
{
_internal = new ISteamRemoteStorage();
_internal.Init();
}
return _internal; internal override void InitializeInterface()
}
}
internal static void Shutdown()
{ {
_internal = null; Internal = new ISteamRemoteStorage();
} }
/// <summary> /// <summary>

View File

@ -10,27 +10,15 @@ namespace Steamworks
/// <summary> /// <summary>
/// Undocumented Parental Settings /// Undocumented Parental Settings
/// </summary> /// </summary>
public static class SteamScreenshots public class SteamScreenshots : SteamClass
{ {
static ISteamScreenshots _internal; internal static ISteamScreenshots Internal;
internal static ISteamScreenshots Internal internal override SteamInterface Interface => Internal;
{
get
{
SteamClient.ValidCheck();
if ( _internal == null ) internal override void InitializeInterface()
{ {
_internal = new ISteamScreenshots(); Internal = new ISteamScreenshots();
_internal.Init(); InstallEvents();
}
return _internal;
}
}
internal static void Shutdown()
{
_internal = null;
} }
internal static void InstallEvents() internal static void InstallEvents()

View File

@ -144,12 +144,6 @@ namespace Steamworks
_internal = null; _internal = null;
ShutdownInterfaces(); ShutdownInterfaces();
SteamNetworkingUtils.Shutdown();
SteamNetworkingSockets.Shutdown();
SteamInventory.Shutdown();
SteamServerStats.Shutdown();
SteamGameServer.Shutdown(); SteamGameServer.Shutdown();
} }

View File

@ -7,26 +7,14 @@ using Steamworks.Data;
namespace Steamworks namespace Steamworks
{ {
public static class SteamServerStats public class SteamServerStats : SteamClass
{ {
static ISteamGameServerStats _internal; internal static ISteamGameServerStats Internal;
internal static ISteamGameServerStats Internal internal override SteamInterface Interface => Internal;
{
get
{
if ( _internal == null )
{
_internal = new ISteamGameServerStats();
_internal.InitServer();
}
return _internal; internal override void InitializeInterface()
}
}
internal static void Shutdown()
{ {
_internal = null; Internal = new ISteamGameServerStats();
} }
/// <summary> /// <summary>
@ -36,7 +24,7 @@ namespace Steamworks
/// </summary> /// </summary>
public static async Task<Result> RequestUserStats( SteamId steamid ) public static async Task<Result> RequestUserStats( SteamId steamid )
{ {
var r = await Internal.RequestUserStats( steamid ); var r = await Internal.RequestUserStats( steamid ).GetAsync<UserStatsReceived_t>();
if ( !r.HasValue ) return Result.Fail; if ( !r.HasValue ) return Result.Fail;
return r.Value.Result; return r.Value.Result;
} }
@ -56,7 +44,7 @@ namespace Steamworks
/// </summary> /// </summary>
public static bool SetFloat( SteamId steamid, string name, float stat ) public static bool SetFloat( SteamId steamid, string name, float stat )
{ {
return Internal.SetUserStat( steamid, name, stat ); return Internal.SetUserStat0( steamid, name, stat );
} }
/// <summary> /// <summary>
@ -68,7 +56,7 @@ namespace Steamworks
{ {
int data = defaultValue; int data = defaultValue;
if ( !Internal.GetUserStat1( steamid, name, ref data ) ) if ( !Internal.GetUserStat( steamid, name, ref data ) )
return defaultValue; return defaultValue;
return data; return data;
@ -83,7 +71,7 @@ namespace Steamworks
{ {
float data = defaultValue; float data = defaultValue;
if ( !Internal.GetUserStat2( steamid, name, ref data ) ) if ( !Internal.GetUserStat0( steamid, name, ref data ) )
return defaultValue; return defaultValue;
return data; return data;
@ -127,7 +115,7 @@ namespace Steamworks
/// </summary> /// </summary>
public static async Task<Result> StoreUserStats( SteamId steamid ) public static async Task<Result> StoreUserStats( SteamId steamid )
{ {
var r = await Internal.StoreUserStats( steamid ); var r = await Internal.StoreUserStats( steamid ).GetAsync<UserStatsStored_t>();
if ( !r.HasValue ) return Result.Fail; if ( !r.HasValue ) return Result.Fail;
return r.Value.Result; return r.Value.Result;
} }

View File

@ -12,21 +12,15 @@ namespace Steamworks
/// Functions for accessing and manipulating Steam user information. /// Functions for accessing and manipulating Steam user information.
/// This is also where the APIs for Steam Voice are exposed. /// This is also where the APIs for Steam Voice are exposed.
/// </summary> /// </summary>
public static class SteamUGC public class SteamUGC : SteamClass
{ {
static ISteamUGC _internal; internal static ISteamUGC Internal;
internal static ISteamUGC Internal internal override SteamInterface Interface => Internal;
{
get
{
if ( _internal == null )
{
_internal = new ISteamUGC();
_internal.Init();
}
return _internal; internal override void InitializeInterface()
} {
Internal = new ISteamUGC();
InstallEvents();
} }
internal static void InstallEvents() internal static void InstallEvents()
@ -39,11 +33,6 @@ namespace Steamworks
/// </summary> /// </summary>
public static event Action<Result> OnDownloadItemResult; public static event Action<Result> OnDownloadItemResult;
internal static void Shutdown()
{
_internal = null;
}
public static async Task<bool> DeleteFileAsync( PublishedFileId fileId ) public static async Task<bool> DeleteFileAsync( PublishedFileId fileId )
{ {
var r = await Internal.DeleteItem( fileId ); var r = await Internal.DeleteItem( fileId );

View File

@ -13,33 +13,20 @@ namespace Steamworks
/// Functions for accessing and manipulating Steam user information. /// Functions for accessing and manipulating Steam user information.
/// This is also where the APIs for Steam Voice are exposed. /// This is also where the APIs for Steam Voice are exposed.
/// </summary> /// </summary>
public static class SteamUser public class SteamUser : SteamClass
{ {
static ISteamUser _internal; internal static ISteamUser Internal;
internal static ISteamUser Internal internal override SteamInterface Interface => Internal;
{
get
{
SteamClient.ValidCheck();
if ( _internal == null ) internal override void InitializeInterface()
{ {
_internal = new ISteamUser(); Internal = new ISteamUser();
_internal.Init(); InstallEvents();
richPresence = new Dictionary<string, string>(); richPresence = new Dictionary<string, string>();
SampleRate = OptimalSampleRate; SampleRate = OptimalSampleRate;
} }
return _internal;
}
}
internal static void Shutdown()
{
_internal = null;
}
static Dictionary<string, string> richPresence; static Dictionary<string, string> richPresence;
internal static void InstallEvents() internal static void InstallEvents()

View File

@ -7,31 +7,19 @@ using Steamworks.Data;
namespace Steamworks namespace Steamworks
{ {
public static class SteamUserStats public class SteamUserStats : SteamClass
{ {
static ISteamUserStats _internal; internal static ISteamUserStats Internal;
internal static ISteamUserStats Internal internal override SteamInterface Interface => Internal;
{
get
{
SteamClient.ValidCheck();
if ( _internal == null ) internal override void InitializeInterface()
{ {
_internal = new ISteamUserStats(); Internal = new ISteamUserStats();
_internal.Init();
InstallEvents();
RequestCurrentStats(); RequestCurrentStats();
} }
return _internal;
}
}
internal static void Shutdown()
{
_internal = null;
}
public static bool StatsRecieved { get; internal set; } public static bool StatsRecieved { get; internal set; }
internal static void InstallEvents() internal static void InstallEvents()

View File

@ -10,26 +10,16 @@ namespace Steamworks
/// <summary> /// <summary>
/// Interface which provides access to a range of miscellaneous utility functions /// Interface which provides access to a range of miscellaneous utility functions
/// </summary> /// </summary>
public static class SteamUtils public class SteamUtils : SteamClass
{ {
static ISteamUtils _internal; internal static ISteamUtils Internal;
internal static ISteamUtils Internal internal override SteamInterface Interface => Internal;
{
get
{
if ( _internal == null )
{
_internal = new ISteamUtils();
_internal.Init();
}
return _internal; internal override void InitializeInterface()
}
}
internal static void Shutdown()
{ {
_internal = null; Internal = new ISteamUtils();
InstallEvents();
} }
internal static void InstallEvents() internal static void InstallEvents()

View File

@ -10,28 +10,16 @@ namespace Steamworks
/// <summary> /// <summary>
/// Undocumented Parental Settings /// Undocumented Parental Settings
/// </summary> /// </summary>
public static class SteamVideo public class SteamVideo : SteamClass
{ {
static ISteamVideo _internal; internal static ISteamVideo Internal;
internal static ISteamVideo Internal internal override SteamInterface Interface => Internal;
{
get
{
SteamClient.ValidCheck();
if ( _internal == null ) internal override void InitializeInterface()
{ {
_internal = new ISteamVideo(); Internal = new ISteamVideo();
_internal.Init();
}
return _internal; InstallEvents();
}
}
internal static void Shutdown()
{
_internal = null;
} }
internal static void InstallEvents() internal static void InstallEvents()

View File

@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
namespace Steamworks
{
internal static class GetApi
{
[DllImport( Platform.LibraryName, EntryPoint = "SteamClient" )]
internal static extern IntPtr SteamClient();
[DllImport( Platform.LibraryName, EntryPoint = "SteamUser" )]
internal static extern IntPtr SteamUser();
[DllImport( Platform.LibraryName, EntryPoint = "SteamFriends" )]
internal static extern IntPtr SteamFriends();
[DllImport( Platform.LibraryName, EntryPoint = "SteamUtils" )]
internal static extern IntPtr SteamUtils();
[DllImport( Platform.LibraryName, EntryPoint = "SteamMatchmaking" )]
internal static extern IntPtr SteamMatchmaking();
[DllImport( Platform.LibraryName, EntryPoint = "SteamMatchmakingServerListResponse" )]
internal static extern IntPtr SteamMatchmakingServerListResponse();
[DllImport( Platform.LibraryName, EntryPoint = "SteamMatchmakingPingResponse" )]
internal static extern IntPtr SteamMatchmakingPingResponse();
[DllImport( Platform.LibraryName, EntryPoint = "SteamMatchmakingPlayersResponse" )]
internal static extern IntPtr SteamMatchmakingPlayersResponse();
[DllImport( Platform.LibraryName, EntryPoint = "SteamMatchmakingRulesResponse" )]
internal static extern IntPtr SteamMatchmakingRulesResponse();
[DllImport( Platform.LibraryName, EntryPoint = "SteamMatchmakingServers" )]
internal static extern IntPtr SteamMatchmakingServers();
[DllImport( Platform.LibraryName, EntryPoint = "SteamGameSearch" )]
internal static extern IntPtr SteamGameSearch();
[DllImport( Platform.LibraryName, EntryPoint = "SteamParties" )]
internal static extern IntPtr SteamParties();
[DllImport( Platform.LibraryName, EntryPoint = "SteamRemoteStorage" )]
internal static extern IntPtr SteamRemoteStorage();
[DllImport( Platform.LibraryName, EntryPoint = "SteamUserStats" )]
internal static extern IntPtr SteamUserStats();
[DllImport( Platform.LibraryName, EntryPoint = "SteamApps" )]
internal static extern IntPtr SteamApps();
[DllImport( Platform.LibraryName, EntryPoint = "SteamNetworking" )]
internal static extern IntPtr SteamNetworking();
[DllImport( Platform.LibraryName, EntryPoint = "SteamScreenshots" )]
internal static extern IntPtr SteamScreenshots();
[DllImport( Platform.LibraryName, EntryPoint = "SteamMusic" )]
internal static extern IntPtr SteamMusic();
[DllImport( Platform.LibraryName, EntryPoint = "SteamMusicRemote" )]
internal static extern IntPtr SteamMusicRemote();
[DllImport( Platform.LibraryName, EntryPoint = "SteamHTTP" )]
internal static extern IntPtr SteamHTTP();
[DllImport( Platform.LibraryName, EntryPoint = "SteamInput" )]
internal static extern IntPtr SteamInput();
[DllImport( Platform.LibraryName, EntryPoint = "SteamController" )]
internal static extern IntPtr SteamController();
[DllImport( Platform.LibraryName, EntryPoint = "SteamUGC" )]
internal static extern IntPtr SteamUGC();
[DllImport( Platform.LibraryName, EntryPoint = "SteamAppList" )]
internal static extern IntPtr SteamAppList();
[DllImport( Platform.LibraryName, EntryPoint = "SteamHTMLSurface" )]
internal static extern IntPtr SteamHTMLSurface();
[DllImport( Platform.LibraryName, EntryPoint = "SteamInventory" )]
internal static extern IntPtr SteamInventory();
[DllImport( Platform.LibraryName, EntryPoint = "SteamVideo" )]
internal static extern IntPtr SteamVideo();
[DllImport( Platform.LibraryName, EntryPoint = "SteamParentalSettings" )]
internal static extern IntPtr SteamParentalSettings();
[DllImport( Platform.LibraryName, EntryPoint = "SteamGameServer" )]
internal static extern IntPtr SteamGameServer();
[DllImport( Platform.LibraryName, EntryPoint = "SteamGameServerStats" )]
internal static extern IntPtr SteamGameServerStats();
}
}

View File

@ -11,103 +11,32 @@ namespace Steamworks
{ {
internal abstract class SteamInterface internal abstract class SteamInterface
{ {
public abstract IntPtr GetInterfacePointer();
public IntPtr Self; public IntPtr Self;
public IntPtr VTable;
public virtual string InterfaceName => null; public bool IsValid => Self != IntPtr.Zero;
public bool IsValid => Self != IntPtr.Zero && VTable != IntPtr.Zero;
public void Init() internal void SetupInterface()
{ {
if ( SteamClient.IsValid ) Self = GetInterfacePointer();
{
InitClient();
return;
} }
if ( SteamServer.IsValid ) internal void ShutdownInterface()
{
InitServer();
return;
}
throw new System.Exception( "Trying to initialize Steam Interface but Steam not initialized" );
}
public void InitClient()
{
//
// There's an issue for us using FindOrCreateUserInterface on Rust.
// We have a different appid for our staging branch, but we use Rust's
// appid so we can still test with the live data/setup. The issue is
// if we run the staging branch and get interfaces using FindOrCreate
// then some callbacks don't work. I assume this is because these interfaces
// have already been initialized using the old appid pipe, but since I
// can't see inside Steam this is just a gut feeling. Either way using
// CreateInterface doesn't seem to have caused any fires, so we'll just use that.
//
//
// var pipe = SteamAPI.GetHSteamPipe();
//
Self = SteamInternal.CreateInterface( InterfaceName );
if ( Self == IntPtr.Zero )
{
var user = SteamAPI.GetHSteamUser();
Self = SteamInternal.FindOrCreateUserInterface( user, InterfaceName );
}
if ( Self == IntPtr.Zero )
throw new System.Exception( $"Couldn't find interface {InterfaceName}" );
VTable = Marshal.ReadIntPtr( Self, 0 );
if ( Self == IntPtr.Zero )
throw new System.Exception( $"Invalid VTable for {InterfaceName}" );
InitInternals();
SteamClient.WatchInterface( this );
}
public void InitServer()
{
var user = SteamGameServer.GetHSteamUser();
Self = SteamInternal.FindOrCreateGameServerInterface( user, InterfaceName );
if ( Self == IntPtr.Zero )
throw new System.Exception( $"Couldn't find server interface {InterfaceName}" );
VTable = Marshal.ReadIntPtr( Self, 0 );
if ( Self == IntPtr.Zero )
throw new System.Exception( $"Invalid VTable for server {InterfaceName}" );
InitInternals();
SteamServer.WatchInterface( this );
}
public virtual void InitUserless()
{
Self = SteamInternal.FindOrCreateUserInterface( 0, InterfaceName );
if ( Self == IntPtr.Zero )
throw new System.Exception( $"Couldn't find interface {InterfaceName}" );
VTable = Marshal.ReadIntPtr( Self, 0 );
if ( Self == IntPtr.Zero )
throw new System.Exception( $"Invalid VTable for {InterfaceName}" );
InitInternals();
}
internal virtual void Shutdown()
{ {
Self = IntPtr.Zero; Self = IntPtr.Zero;
VTable = IntPtr.Zero; }
} }
public abstract void InitInternals(); public abstract class SteamClass
{
internal abstract void InitializeInterface();
internal void DestroyInterface()
{
Interface.ShutdownInterface();
} }
internal abstract SteamInterface Interface { get; }
}
} }

View File

@ -25,11 +25,7 @@ namespace Generator
{ {
StartBlock( $"internal class {className} : SteamInterface" ); StartBlock( $"internal class {className} : SteamInterface" );
{ {
//WriteLine( $"public override string InterfaceName => \"{clss.InterfaceString}\";" ); WriteLine( $"public override IntPtr GetInterfacePointer() => GetApi.{className.Substring( 1 )}();" );
//WriteLine();
WriteFunctionPointerReader();
WriteLine(); WriteLine();
var functions = def.methods.Where( x => x.ClassName == className ); var functions = def.methods.Where( x => x.ClassName == className );
@ -50,22 +46,6 @@ namespace Generator
System.IO.File.WriteAllText( $"{filename}", sb.ToString() ); System.IO.File.WriteAllText( $"{filename}", sb.ToString() );
} }
void WriteFunctionPointerReader()
{
StartBlock( $"public override void InitInternals()" );
{
}
EndBlock();
StartBlock( $"internal override void Shutdown()" );
{
WriteLine( $"base.Shutdown();" );
WriteLine( "" );
}
EndBlock();
}
private void WriteFunction( SteamApiDefinition.MethodDef func ) private void WriteFunction( SteamApiDefinition.MethodDef func )
{ {
var returnType = BaseType.Parse( func.ReturnType ); var returnType = BaseType.Parse( func.ReturnType );