Global function cleanup

This commit is contained in:
Garry Newman 2019-06-25 12:13:04 +01:00
parent d5abb32aeb
commit f53e1aaba0
5 changed files with 59 additions and 355 deletions

View File

@ -9,234 +9,89 @@ namespace Steamworks
{ {
internal static class SteamAPI internal static class SteamAPI
{ {
internal static class Win64 internal static class Native
{ {
[DllImport( "steam_api64", EntryPoint = "SteamAPI_Init", CallingConvention = CallingConvention.Cdecl )] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_Init", CallingConvention = CallingConvention.Cdecl )]
[return: MarshalAs( UnmanagedType.I1 )] [return: MarshalAs( UnmanagedType.I1 )]
public static extern bool SteamAPI_Init(); public static extern bool SteamAPI_Init();
[DllImport( "steam_api64", EntryPoint = "SteamAPI_RunCallbacks", CallingConvention = CallingConvention.Cdecl )] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_RunCallbacks", CallingConvention = CallingConvention.Cdecl )]
public static extern void SteamAPI_RunCallbacks(); public static extern void SteamAPI_RunCallbacks();
[DllImport( "steam_api64", EntryPoint = "SteamAPI_RegisterCallback", CallingConvention = CallingConvention.Cdecl )] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_RegisterCallback", CallingConvention = CallingConvention.Cdecl )]
public static extern void SteamAPI_RegisterCallback( IntPtr pCallback, int callback ); public static extern void SteamAPI_RegisterCallback( IntPtr pCallback, int callback );
[DllImport( "steam_api64", EntryPoint = "SteamAPI_UnregisterCallback", CallingConvention = CallingConvention.Cdecl )] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_UnregisterCallback", CallingConvention = CallingConvention.Cdecl )]
public static extern void SteamAPI_UnregisterCallback( IntPtr pCallback ); public static extern void SteamAPI_UnregisterCallback( IntPtr pCallback );
[DllImport( "steam_api64", EntryPoint = "SteamAPI_RegisterCallResult", CallingConvention = CallingConvention.Cdecl )] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_RegisterCallResult", CallingConvention = CallingConvention.Cdecl )]
public static extern void SteamAPI_RegisterCallResult( IntPtr pCallback, SteamAPICall_t callback ); public static extern void SteamAPI_RegisterCallResult( IntPtr pCallback, SteamAPICall_t callback );
[DllImport( "steam_api64", EntryPoint = "SteamAPI_UnregisterCallResult", CallingConvention = CallingConvention.Cdecl )] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_UnregisterCallResult", CallingConvention = CallingConvention.Cdecl )]
public static extern void SteamAPI_UnregisterCallResult( IntPtr pCallback, SteamAPICall_t callback ); public static extern void SteamAPI_UnregisterCallResult( IntPtr pCallback, SteamAPICall_t callback );
[DllImport( "steam_api64", EntryPoint = "SteamAPI_Shutdown", CallingConvention = CallingConvention.Cdecl )] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_Shutdown", CallingConvention = CallingConvention.Cdecl )]
public static extern void SteamAPI_Shutdown(); public static extern void SteamAPI_Shutdown();
[DllImport( "steam_api64", EntryPoint = "SteamAPI_GetHSteamUser", CallingConvention = CallingConvention.Cdecl )] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_GetHSteamUser", CallingConvention = CallingConvention.Cdecl )]
public static extern HSteamUser SteamAPI_GetHSteamUser(); public static extern HSteamUser SteamAPI_GetHSteamUser();
[DllImport( "steam_api64", EntryPoint = "SteamAPI_GetHSteamPipe", CallingConvention = CallingConvention.Cdecl )] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_GetHSteamPipe", CallingConvention = CallingConvention.Cdecl )]
public static extern HSteamPipe SteamAPI_GetHSteamPipe(); public static extern HSteamPipe SteamAPI_GetHSteamPipe();
[DllImport( "steam_api64", EntryPoint = "SteamAPI_RestartAppIfNecessary", CallingConvention = CallingConvention.Cdecl )] [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_RestartAppIfNecessary", CallingConvention = CallingConvention.Cdecl )]
[return: MarshalAs( UnmanagedType.I1 )]
public static extern bool SteamAPI_RestartAppIfNecessary( uint unOwnAppID );
}
internal static class Posix
{
[DllImport( "libsteam_api", EntryPoint = "SteamAPI_Init", CallingConvention = CallingConvention.Cdecl )]
[return: MarshalAs( UnmanagedType.I1 )]
public static extern bool SteamAPI_Init();
[DllImport( "libsteam_api", EntryPoint = "SteamAPI_RunCallbacks", CallingConvention = CallingConvention.Cdecl )]
public static extern void SteamAPI_RunCallbacks();
[DllImport( "libsteam_api", EntryPoint = "SteamAPI_RegisterCallback", CallingConvention = CallingConvention.Cdecl )]
public static extern void SteamAPI_RegisterCallback( IntPtr pCallback, int callback );
[DllImport( "libsteam_api", EntryPoint = "SteamAPI_UnregisterCallback", CallingConvention = CallingConvention.Cdecl )]
public static extern void SteamAPI_UnregisterCallback( IntPtr pCallback );
[DllImport( "libsteam_api", EntryPoint = "SteamAPI_RegisterCallResult", CallingConvention = CallingConvention.Cdecl )]
public static extern void SteamAPI_RegisterCallResult( IntPtr pCallback, SteamAPICall_t callback );
[DllImport( "libsteam_api", EntryPoint = "SteamAPI_UnregisterCallResult", CallingConvention = CallingConvention.Cdecl )]
public static extern void SteamAPI_UnregisterCallResult( IntPtr pCallback, SteamAPICall_t callback );
[DllImport( "libsteam_api", EntryPoint = "SteamAPI_Shutdown", CallingConvention = CallingConvention.Cdecl )]
public static extern void SteamAPI_Shutdown();
[DllImport( "libsteam_api", EntryPoint = "SteamAPI_GetHSteamUser", CallingConvention = CallingConvention.Cdecl )]
public static extern HSteamUser SteamAPI_GetHSteamUser();
[DllImport( "libsteam_api", EntryPoint = "SteamAPI_GetHSteamPipe", CallingConvention = CallingConvention.Cdecl )]
public static extern HSteamPipe SteamAPI_GetHSteamPipe();
[DllImport( "libsteam_api", EntryPoint = "SteamAPI_RestartAppIfNecessary", CallingConvention = CallingConvention.Cdecl )]
[return: MarshalAs( UnmanagedType.I1 )] [return: MarshalAs( UnmanagedType.I1 )]
public static extern bool SteamAPI_RestartAppIfNecessary( uint unOwnAppID ); public static extern bool SteamAPI_RestartAppIfNecessary( uint unOwnAppID );
} }
static internal bool Init() static internal bool Init()
{ {
if ( Config.Os == OsType.Windows ) return Native.SteamAPI_Init();
{
return Win64.SteamAPI_Init();
}
else if ( Config.Os == OsType.Posix )
{
return Posix.SteamAPI_Init();
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
} }
static internal void RunCallbacks() static internal void RunCallbacks()
{ {
if ( Config.Os == OsType.Windows ) Native.SteamAPI_RunCallbacks();
{
Win64.SteamAPI_RunCallbacks();
}
else if ( Config.Os == OsType.Posix )
{
Posix.SteamAPI_RunCallbacks();
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
} }
static internal void RegisterCallback( IntPtr pCallback, int callback ) static internal void RegisterCallback( IntPtr pCallback, int callback )
{ {
if ( Config.Os == OsType.Windows ) Native.SteamAPI_RegisterCallback( pCallback, callback );
{
Win64.SteamAPI_RegisterCallback( pCallback, callback );
}
else if ( Config.Os == OsType.Posix )
{
Posix.SteamAPI_RegisterCallback( pCallback, callback );
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
} }
static internal void UnregisterCallback( IntPtr pCallback ) static internal void UnregisterCallback( IntPtr pCallback )
{ {
if ( Config.Os == OsType.Windows ) Native.SteamAPI_UnregisterCallback( pCallback );
{
Win64.SteamAPI_UnregisterCallback( pCallback );
}
else if ( Config.Os == OsType.Posix )
{
Posix.SteamAPI_UnregisterCallback( pCallback );
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
} }
static internal void RegisterCallResult( IntPtr pCallback, SteamAPICall_t callback ) static internal void RegisterCallResult( IntPtr pCallback, SteamAPICall_t callback )
{ {
if ( Config.Os == OsType.Windows ) Native.SteamAPI_RegisterCallResult( pCallback, callback );
{
Win64.SteamAPI_RegisterCallResult( pCallback, callback );
}
else if ( Config.Os == OsType.Posix )
{
Posix.SteamAPI_RegisterCallResult( pCallback, callback );
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
} }
static internal void UnregisterCallResult( IntPtr pCallback, SteamAPICall_t callback ) static internal void UnregisterCallResult( IntPtr pCallback, SteamAPICall_t callback )
{ {
if ( Config.Os == OsType.Windows ) Native.SteamAPI_UnregisterCallResult( pCallback, callback );
{
Win64.SteamAPI_UnregisterCallResult( pCallback, callback );
}
else if ( Config.Os == OsType.Posix )
{
Posix.SteamAPI_UnregisterCallResult( pCallback, callback );
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
} }
static internal void Shutdown() static internal void Shutdown()
{ {
if ( Config.Os == OsType.Windows ) Native.SteamAPI_Shutdown();
{
Win64.SteamAPI_Shutdown();
}
else if ( Config.Os == OsType.Posix )
{
Posix.SteamAPI_Shutdown();
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
} }
static internal HSteamUser GetHSteamUser() static internal HSteamUser GetHSteamUser()
{ {
if ( Config.Os == OsType.Windows ) return Native.SteamAPI_GetHSteamUser();
{
return Win64.SteamAPI_GetHSteamUser();
}
else if ( Config.Os == OsType.Posix )
{
return Posix.SteamAPI_GetHSteamUser();
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
} }
static internal HSteamPipe GetHSteamPipe() static internal HSteamPipe GetHSteamPipe()
{ {
if ( Config.Os == OsType.Windows ) return Native.SteamAPI_GetHSteamPipe();
{
return Win64.SteamAPI_GetHSteamPipe();
}
else if ( Config.Os == OsType.Posix )
{
return Posix.SteamAPI_GetHSteamPipe();
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
} }
static internal bool RestartAppIfNecessary( uint unOwnAppID ) static internal bool RestartAppIfNecessary( uint unOwnAppID )
{ {
if ( Config.Os == OsType.Windows ) return Native.SteamAPI_RestartAppIfNecessary( unOwnAppID );
{
return Win64.SteamAPI_RestartAppIfNecessary( unOwnAppID );
}
else if ( Config.Os == OsType.Posix )
{
return Posix.SteamAPI_RestartAppIfNecessary( unOwnAppID );
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
} }
} }

View File

@ -9,98 +9,39 @@ namespace Steamworks
{ {
internal static class SteamGameServer internal static class SteamGameServer
{ {
internal static class Win64 internal static class Native
{ {
[DllImport( "steam_api64", EntryPoint = "SteamGameServer_RunCallbacks", CallingConvention = CallingConvention.Cdecl )] [DllImport( Platform.LibraryName, EntryPoint = "SteamGameServer_RunCallbacks", CallingConvention = CallingConvention.Cdecl )]
public static extern void SteamGameServer_RunCallbacks(); public static extern void SteamGameServer_RunCallbacks();
[DllImport( "steam_api64", EntryPoint = "SteamGameServer_Shutdown", CallingConvention = CallingConvention.Cdecl )] [DllImport( Platform.LibraryName, EntryPoint = "SteamGameServer_Shutdown", CallingConvention = CallingConvention.Cdecl )]
public static extern void SteamGameServer_Shutdown(); public static extern void SteamGameServer_Shutdown();
[DllImport( "steam_api64", EntryPoint = "SteamGameServer_GetHSteamUser", CallingConvention = CallingConvention.Cdecl )] [DllImport( Platform.LibraryName, EntryPoint = "SteamGameServer_GetHSteamUser", CallingConvention = CallingConvention.Cdecl )]
public static extern HSteamUser SteamGameServer_GetHSteamUser(); public static extern HSteamUser SteamGameServer_GetHSteamUser();
[DllImport( "steam_api64", EntryPoint = "SteamGameServer_GetHSteamPipe", CallingConvention = CallingConvention.Cdecl )] [DllImport( Platform.LibraryName, EntryPoint = "SteamGameServer_GetHSteamPipe", CallingConvention = CallingConvention.Cdecl )]
public static extern HSteamPipe SteamGameServer_GetHSteamPipe();
}
internal static class Posix
{
[DllImport( "libsteam_api", EntryPoint = "SteamGameServer_RunCallbacks", CallingConvention = CallingConvention.Cdecl )]
public static extern void SteamGameServer_RunCallbacks();
[DllImport( "libsteam_api", EntryPoint = "SteamGameServer_Shutdown", CallingConvention = CallingConvention.Cdecl )]
public static extern void SteamGameServer_Shutdown();
[DllImport( "libsteam_api", EntryPoint = "SteamGameServer_GetHSteamUser", CallingConvention = CallingConvention.Cdecl )]
public static extern HSteamUser SteamGameServer_GetHSteamUser();
[DllImport( "libsteam_api", EntryPoint = "SteamGameServer_GetHSteamPipe", CallingConvention = CallingConvention.Cdecl )]
public static extern HSteamPipe SteamGameServer_GetHSteamPipe(); public static extern HSteamPipe SteamGameServer_GetHSteamPipe();
} }
static internal void RunCallbacks() static internal void RunCallbacks()
{ {
if ( Config.Os == OsType.Windows ) Native.SteamGameServer_RunCallbacks();
{
Win64.SteamGameServer_RunCallbacks();
}
else if ( Config.Os == OsType.Posix )
{
Posix.SteamGameServer_RunCallbacks();
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
} }
static internal void Shutdown() static internal void Shutdown()
{ {
if ( Config.Os == OsType.Windows ) Native.SteamGameServer_Shutdown();
{
Win64.SteamGameServer_Shutdown();
}
else if ( Config.Os == OsType.Posix )
{
Posix.SteamGameServer_Shutdown();
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
} }
static internal HSteamUser GetHSteamUser() static internal HSteamUser GetHSteamUser()
{ {
if ( Config.Os == OsType.Windows ) return Native.SteamGameServer_GetHSteamUser();
{
return Win64.SteamGameServer_GetHSteamUser();
}
else if ( Config.Os == OsType.Posix )
{
return Posix.SteamGameServer_GetHSteamUser();
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
} }
static internal HSteamPipe GetHSteamPipe() static internal HSteamPipe GetHSteamPipe()
{ {
if ( Config.Os == OsType.Windows ) return Native.SteamGameServer_GetHSteamPipe();
{
return Win64.SteamGameServer_GetHSteamPipe();
}
else if ( Config.Os == OsType.Posix )
{
return Posix.SteamGameServer_GetHSteamPipe();
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
} }
} }

View File

@ -9,100 +9,40 @@ namespace Steamworks
{ {
internal static class SteamInternal internal static class SteamInternal
{ {
internal static class Win64 internal static class Native
{ {
[DllImport( "steam_api64", EntryPoint = "SteamInternal_GameServer_Init", CallingConvention = CallingConvention.Cdecl )] [DllImport( Platform.LibraryName, EntryPoint = "SteamInternal_GameServer_Init", CallingConvention = CallingConvention.Cdecl )]
[return: MarshalAs( UnmanagedType.I1 )] [return: MarshalAs( UnmanagedType.I1 )]
public static extern bool SteamInternal_GameServer_Init( uint unIP, ushort usPort, ushort usGamePort, ushort usQueryPort, int eServerMode, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string pchVersionString ); public static extern bool SteamInternal_GameServer_Init( uint unIP, ushort usPort, ushort usGamePort, ushort usQueryPort, int eServerMode, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string pchVersionString );
[DllImport( "steam_api64", EntryPoint = "SteamInternal_FindOrCreateUserInterface", CallingConvention = CallingConvention.Cdecl )] [DllImport( Platform.LibraryName, EntryPoint = "SteamInternal_FindOrCreateUserInterface", CallingConvention = CallingConvention.Cdecl )]
public static extern IntPtr SteamInternal_FindOrCreateUserInterface( int steamuser, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string versionname ); public static extern IntPtr SteamInternal_FindOrCreateUserInterface( int steamuser, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string versionname );
[DllImport( "steam_api64", EntryPoint = "SteamInternal_FindOrCreateGameServerInterface", CallingConvention = CallingConvention.Cdecl )] [DllImport( Platform.LibraryName, EntryPoint = "SteamInternal_FindOrCreateGameServerInterface", CallingConvention = CallingConvention.Cdecl )]
public static extern IntPtr SteamInternal_FindOrCreateGameServerInterface( int steamuser, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string versionname ); public static extern IntPtr SteamInternal_FindOrCreateGameServerInterface( int steamuser, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string versionname );
[DllImport( "steam_api64", EntryPoint = "SteamInternal_CreateInterface", CallingConvention = CallingConvention.Cdecl )] [DllImport( Platform.LibraryName, EntryPoint = "SteamInternal_CreateInterface", CallingConvention = CallingConvention.Cdecl )]
public static extern IntPtr SteamInternal_CreateInterface( [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string version );
}
internal static class Posix
{
[DllImport( "libsteam_api", EntryPoint = "SteamInternal_GameServer_Init", CallingConvention = CallingConvention.Cdecl )]
[return: MarshalAs( UnmanagedType.I1 )]
public static extern bool SteamInternal_GameServer_Init( uint unIP, ushort usPort, ushort usGamePort, ushort usQueryPort, int eServerMode, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string pchVersionString );
[DllImport( "libsteam_api", EntryPoint = "SteamInternal_FindOrCreateUserInterface", CallingConvention = CallingConvention.Cdecl )]
public static extern IntPtr SteamInternal_FindOrCreateUserInterface( int steamuser, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string versionname );
[DllImport( "libsteam_api", EntryPoint = "SteamInternal_FindOrCreateGameServerInterface", CallingConvention = CallingConvention.Cdecl )]
public static extern IntPtr SteamInternal_FindOrCreateGameServerInterface( int steamuser, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string versionname );
[DllImport( "libsteam_api", EntryPoint = "SteamInternal_CreateInterface", CallingConvention = CallingConvention.Cdecl )]
public static extern IntPtr SteamInternal_CreateInterface( [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string version ); public static extern IntPtr SteamInternal_CreateInterface( [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string version );
} }
static internal bool GameServer_Init( uint unIP, ushort usPort, ushort usGamePort, ushort usQueryPort, int eServerMode, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string pchVersionString ) static internal bool GameServer_Init( uint unIP, ushort usPort, ushort usGamePort, ushort usQueryPort, int eServerMode, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string pchVersionString )
{ {
if ( Config.Os == OsType.Windows ) return Native.SteamInternal_GameServer_Init( unIP, usPort, usGamePort, usQueryPort, eServerMode, pchVersionString );
{
return Win64.SteamInternal_GameServer_Init( unIP, usPort, usGamePort, usQueryPort, eServerMode, pchVersionString );
}
else if ( Config.Os == OsType.Posix )
{
return Posix.SteamInternal_GameServer_Init( unIP, usPort, usGamePort, usQueryPort, eServerMode, pchVersionString );
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
} }
static internal IntPtr FindOrCreateUserInterface( int steamuser, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string versionname ) static internal IntPtr FindOrCreateUserInterface( int steamuser, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string versionname )
{ {
if ( Config.Os == OsType.Windows ) return Native.SteamInternal_FindOrCreateUserInterface( steamuser, versionname );
{
return Win64.SteamInternal_FindOrCreateUserInterface( steamuser, versionname );
}
else if ( Config.Os == OsType.Posix )
{
return Posix.SteamInternal_FindOrCreateUserInterface( steamuser, versionname );
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
} }
static internal IntPtr FindOrCreateGameServerInterface( int steamuser, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string versionname ) static internal IntPtr FindOrCreateGameServerInterface( int steamuser, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string versionname )
{ {
if ( Config.Os == OsType.Windows ) return Native.SteamInternal_FindOrCreateGameServerInterface( steamuser, versionname );
{
return Win64.SteamInternal_FindOrCreateGameServerInterface( steamuser, versionname );
}
else if ( Config.Os == OsType.Posix )
{
return Posix.SteamInternal_FindOrCreateGameServerInterface( steamuser, versionname );
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
} }
static internal IntPtr CreateInterface( [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string version ) static internal IntPtr CreateInterface( [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string version )
{ {
if ( Config.Os == OsType.Windows ) return Native.SteamInternal_CreateInterface( version );
{
return Win64.SteamInternal_CreateInterface( version );
}
else if ( Config.Os == OsType.Posix )
{
return Posix.SteamInternal_CreateInterface( version );
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
} }
} }

View File

@ -11,8 +11,13 @@ internal static class Platform
{ {
#if PLATFORM_WIN64 #if PLATFORM_WIN64
public const int StructPlatformPackSize = 8; public const int StructPlatformPackSize = 8;
#else public const string LibraryName = "steam_api64";
#elif PLATFORM_WIN32
public const int StructPlatformPackSize = 4; public const int StructPlatformPackSize = 4;
public const string LibraryName = "steam_api";
#elif PLATFORM_POSIX64
public const int StructPlatformPackSize = 4;
public const string LibraryName = "libsteam_api";
#endif #endif
public const int StructPackSize = 4; public const int StructPackSize = 4;

View File

@ -27,20 +27,11 @@ public void GenerateGlobalFunctions( string startingWith, string filename )
{ {
StartBlock( $"internal static class {startingWith}" ); StartBlock( $"internal static class {startingWith}" );
{ {
StartBlock( $"internal static class Win64" ); StartBlock( $"internal static class Native" );
{ {
foreach ( var func in functions ) foreach ( var func in functions )
{ {
WriteMarshalledFunction( func, "steam_api64" ); WriteMarshalledFunction( func );
}
}
EndBlock();
StartBlock( $"internal static class Posix" );
{
foreach ( var func in functions )
{
WriteMarshalledFunction( func, "libsteam_api" );
} }
} }
EndBlock(); EndBlock();
@ -87,56 +78,28 @@ private void WriteGlobalFunction( string cname, SteamApiDefinition.MethodDef fun
{ {
var callargs = string.Join( ", ", args.Select( x => x.AsCallArgument() ) ); var callargs = string.Join( ", ", args.Select( x => x.AsCallArgument() ) );
StartBlock( "if ( Config.Os == OsType.Windows )" ); if ( returnType.IsReturnedWeird )
{ {
WriteLine( $"var retVal = default( {returnType.TypeName} );" );
if ( returnType.IsReturnedWeird ) WriteLine( $"Native.{func.Name}( ref retVal, {callargs} );" );
{ WriteLine( $"{returnType.Return( "retVal" )}" );
WriteLine( $"var retVal = default( {returnType.TypeName} );" );
WriteLine( $"Win64.{func.Name}( ref retVal, {callargs} );" );
WriteLine( $"{returnType.Return( "retVal" )}" );
}
else if ( returnType.IsVoid )
{
WriteLine( $"Win64.{func.Name}( {callargs} );" );
}
else
{
var v = $"Win64.{func.Name}( {callargs} )";
WriteLine( returnType.Return( v ) );
}
} }
Else( " if ( Config.Os == OsType.Posix )" ); else if ( returnType.IsVoid )
{ {
if ( returnType.IsReturnedWeird ) WriteLine( $"Native.{func.Name}( {callargs} );" );
{
WriteLine( $"var retVal = default( {returnType.TypeName} );" );
WriteLine( $"Posix.{func.Name}( ref retVal, {callargs} );" );
WriteLine( $"{returnType.Return( "retVal" )}" );
}
else if ( returnType.IsVoid )
{
WriteLine( $"Posix.{func.Name}( {callargs} );" );
}
else
{
var v = $"Posix.{func.Name}( {callargs} )";
WriteLine( returnType.Return( v ) );
}
} }
Else(); else
{ {
WriteLine( "throw new System.Exception( \"this platform isn't supported\" );" ); var v = $"Native.{func.Name}( {callargs} )";
WriteLine( returnType.Return( v ) );
} }
EndBlock();
} }
EndBlock(); EndBlock();
} }
private void WriteMarshalledFunction( SteamApiDefinition.MethodDef func, string dllName ) private void WriteMarshalledFunction( SteamApiDefinition.MethodDef func )
{ {
var returnType = BaseType.Parse( func.ReturnType ); var returnType = BaseType.Parse( func.ReturnType );
returnType.Func = func.Name; returnType.Func = func.Name;
@ -153,7 +116,7 @@ private void WriteMarshalledFunction( SteamApiDefinition.MethodDef func, string
var argstr = string.Join( ", ", args.Select( x => x.AsArgument() ) ); var argstr = string.Join( ", ", args.Select( x => x.AsArgument() ) );
var delegateargstr = string.Join( ", ", args.Select( x => x.AsArgument() ) ); var delegateargstr = string.Join( ", ", args.Select( x => x.AsArgument() ) );
WriteLine( $"[DllImport( \"{dllName}\", EntryPoint = \"{func.Name}\", CallingConvention = CallingConvention.Cdecl )]" ); WriteLine( $"[DllImport( Platform.LibraryName, EntryPoint = \"{func.Name}\", CallingConvention = CallingConvention.Cdecl )]" );
if ( returnType.ReturnAttribute != null ) if ( returnType.ReturnAttribute != null )
WriteLine( returnType.ReturnAttribute ); WriteLine( returnType.ReturnAttribute );