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
{
public override void InitInternals()
{
}
internal override void Shutdown()
{
base.Shutdown();
}
public override IntPtr GetInterfacePointer() => GetApi.SteamApps();
#region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamApps_BIsSubscribed")]

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -29,22 +29,24 @@ namespace Steamworks
initialized = true;
SteamApps.InstallEvents();
SteamUtils.InstallEvents();
SteamParental.InstallEvents();
SteamMusic.InstallEvents();
SteamVideo.InstallEvents();
SteamUser.InstallEvents();
SteamFriends.InstallEvents();
SteamScreenshots.InstallEvents();
SteamUserStats.InstallEvents();
SteamInventory.InstallEvents();
SteamNetworking.InstallEvents();
SteamMatchmaking.InstallEvents();
SteamParties.InstallEvents();
SteamNetworkingSockets.InstallEvents();
SteamInput.InstallEvents();
SteamUGC.InstallEvents();
AddInterface<SteamApps>();
AddInterface<SteamFriends>();
AddInterface<SteamInput>();
AddInterface<SteamInventory>();
AddInterface<SteamMatchmaking>();
AddInterface<SteamMusic>();
AddInterface<SteamNetworking>();
AddInterface<SteamNetworkingSockets>();
AddInterface<SteamNetworkingUtils>();
AddInterface<SteamParental>();
AddInterface<SteamParties>();
AddInterface<SteamRemoteStorage>();
AddInterface<SteamScreenshots>();
AddInterface<SteamUGC>();
AddInterface<SteamUser>();
AddInterface<SteamUserStats>();
AddInterface<SteamUtils>();
AddInterface<SteamVideo>();
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 )
{
if ( openIterfaces.Contains( steamInterface ) )
if ( openInterfaces.Contains( steamInterface ) )
throw new System.Exception( "openIterfaces already contains interface!" );
openIterfaces.Add( steamInterface );
openInterfaces.Add( steamInterface );
}
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;
@ -97,8 +104,6 @@ namespace Steamworks
{
if ( !IsValid ) return;
SteamInput.Shutdown();
Cleanup();
SteamAPI.Shutdown();
@ -111,22 +116,6 @@ namespace Steamworks
Event.DisposeAllClient();
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();
}

View File

@ -10,29 +10,16 @@ namespace Steamworks
/// <summary>
/// Undocumented Parental Settings
/// </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;
internal override void InitializeInterface()
{
get
{
SteamClient.ValidCheck();
Internal = new ISteamFriends();
if ( _internal == null )
{
_internal = new ISteamFriends();
_internal.Init();
richPresence = new Dictionary<string, string>();
}
return _internal;
}
}
internal static void Shutdown()
{
_internal = null;
richPresence = new Dictionary<string, string>();
}
static Dictionary<string, string> richPresence;

View File

@ -3,44 +3,18 @@ using System.Collections.Generic;
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;
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>
/// You shouldn't really need to call this because it get called by RunCallbacks on SteamClient

View File

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

View File

@ -10,37 +10,25 @@ namespace Steamworks
/// <summary>
/// Functions for clients to access matchmaking services, favorites, and to operate on game lobbies
/// </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>
/// Maximum number of characters a lobby metadata key can be
/// </summary>
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()
{
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.
/// Nothing uses Steam Music though so this can probably get fucked
/// </summary>
public static class SteamMusic
public class SteamMusic : SteamClass
{
static ISteamMusic _internal;
internal static ISteamMusic Internal
{
get
{
SteamClient.ValidCheck();
internal static ISteamMusic Internal;
internal override SteamInterface Interface => Internal;
if ( _internal == null )
{
_internal = new ISteamMusic();
_internal.Init();
}
return _internal;
}
}
internal static void Shutdown()
internal override void InitializeInterface()
{
_internal = null;
Internal = new ISteamMusic();
InstallEvents();
}
internal static void InstallEvents()

View File

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

View File

@ -8,24 +8,19 @@ using Steamworks.Data;
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
{
if ( _internal == null )
{
_internal = new ISteamNetworkingSockets();
_internal.Init();
Internal = new ISteamNetworkingSockets();
SocketInterfaces = new Dictionary<uint, SocketInterface>();
ConnectionInterfaces = new Dictionary<uint, ConnectionInterface>();
}
SocketInterfaces = new Dictionary<uint, SocketInterface>();
ConnectionInterfaces = new Dictionary<uint, ConnectionInterface>();
return _internal;
}
InstallEvents();
}
#region SocketInterface
@ -74,13 +69,6 @@ namespace Steamworks
}
#endregion
internal static void Shutdown()
{
_internal = null;
SocketInterfaces = null;
ConnectionInterfaces = null;
}
internal static void InstallEvents( bool server = false )
{
SteamNetConnectionStatusChangedCallback_t.Install( x => ConnectionStatusChanged( x ), server );

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -13,31 +13,18 @@ namespace Steamworks
/// Functions for accessing and manipulating Steam user information.
/// This is also where the APIs for Steam Voice are exposed.
/// </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;
internal override void InitializeInterface()
{
get
{
SteamClient.ValidCheck();
Internal = new ISteamUser();
InstallEvents();
if ( _internal == null )
{
_internal = new ISteamUser();
_internal.Init();
richPresence = new Dictionary<string, string>();
SampleRate = OptimalSampleRate;
}
return _internal;
}
}
internal static void Shutdown()
{
_internal = null;
richPresence = new Dictionary<string, string>();
SampleRate = OptimalSampleRate;
}
static Dictionary<string, string> richPresence;

View File

@ -7,29 +7,17 @@ using Steamworks.Data;
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;
internal override void InitializeInterface()
{
get
{
SteamClient.ValidCheck();
Internal = new ISteamUserStats();
if ( _internal == null )
{
_internal = new ISteamUserStats();
_internal.Init();
RequestCurrentStats();
}
return _internal;
}
}
internal static void Shutdown()
{
_internal = null;
InstallEvents();
RequestCurrentStats();
}
public static bool StatsRecieved { get; internal set; }

View File

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

View File

@ -10,28 +10,16 @@ namespace Steamworks
/// <summary>
/// Undocumented Parental Settings
/// </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;
internal override void InitializeInterface()
{
get
{
SteamClient.ValidCheck();
Internal = new ISteamVideo();
if ( _internal == null )
{
_internal = new ISteamVideo();
_internal.Init();
}
return _internal;
}
}
internal static void Shutdown()
{
_internal = null;
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
{
public abstract IntPtr GetInterfacePointer();
public IntPtr Self;
public IntPtr VTable;
public virtual string InterfaceName => null;
public bool IsValid => Self != IntPtr.Zero && VTable != IntPtr.Zero;
public bool IsValid => Self != IntPtr.Zero;
public void Init()
internal void SetupInterface()
{
if ( SteamClient.IsValid )
{
InitClient();
return;
}
if ( SteamServer.IsValid )
{
InitServer();
return;
}
throw new System.Exception( "Trying to initialize Steam Interface but Steam not initialized" );
Self = GetInterfacePointer();
}
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()
internal void ShutdownInterface()
{
Self = IntPtr.Zero;
VTable = IntPtr.Zero;
}
}
public abstract class SteamClass
{
internal abstract void InitializeInterface();
internal void DestroyInterface()
{
Interface.ShutdownInterface();
}
public abstract void InitInternals();
internal abstract SteamInterface Interface { get; }
}
}

View File

@ -25,11 +25,7 @@ namespace Generator
{
StartBlock( $"internal class {className} : SteamInterface" );
{
//WriteLine( $"public override string InterfaceName => \"{clss.InterfaceString}\";" );
//WriteLine();
WriteFunctionPointerReader();
WriteLine( $"public override IntPtr GetInterfacePointer() => GetApi.{className.Substring( 1 )}();" );
WriteLine();
var functions = def.methods.Where( x => x.ClassName == className );
@ -50,22 +46,6 @@ namespace Generator
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 )
{
var returnType = BaseType.Parse( func.ReturnType );