From f53e1aaba061642ffa7e7a3536f90dd2d180a8b4 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Tue, 25 Jun 2019 12:13:04 +0100 Subject: [PATCH] Global function cleanup --- Facepunch.Steamworks/Generated/SteamApi.cs | 187 ++---------------- .../Generated/SteamGameServer.cs | 77 +------- .../Generated/SteamInternal.cs | 78 +------- Facepunch.Steamworks/Utility/Platform.cs | 7 +- Generator/CodeWriter/GlobalFunctions.cs | 65 ++---- 5 files changed, 59 insertions(+), 355 deletions(-) diff --git a/Facepunch.Steamworks/Generated/SteamApi.cs b/Facepunch.Steamworks/Generated/SteamApi.cs index 43f2367..e65a2bd 100644 --- a/Facepunch.Steamworks/Generated/SteamApi.cs +++ b/Facepunch.Steamworks/Generated/SteamApi.cs @@ -9,234 +9,89 @@ namespace Steamworks { 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 )] 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(); - [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 ); - [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 ); - [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 ); - [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 ); - [DllImport( "steam_api64", EntryPoint = "SteamAPI_Shutdown", CallingConvention = CallingConvention.Cdecl )] + [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_Shutdown", CallingConvention = CallingConvention.Cdecl )] 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(); - [DllImport( "steam_api64", EntryPoint = "SteamAPI_GetHSteamPipe", CallingConvention = CallingConvention.Cdecl )] + [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_GetHSteamPipe", CallingConvention = CallingConvention.Cdecl )] public static extern HSteamPipe SteamAPI_GetHSteamPipe(); - [DllImport( "steam_api64", 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 )] + [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_RestartAppIfNecessary", CallingConvention = CallingConvention.Cdecl )] [return: MarshalAs( UnmanagedType.I1 )] public static extern bool SteamAPI_RestartAppIfNecessary( uint unOwnAppID ); } static internal bool Init() { - if ( Config.Os == OsType.Windows ) - { - return Win64.SteamAPI_Init(); - } - else if ( Config.Os == OsType.Posix ) - { - return Posix.SteamAPI_Init(); - } - else - { - throw new System.Exception( "this platform isn't supported" ); - } + return Native.SteamAPI_Init(); } static internal void RunCallbacks() { - if ( Config.Os == OsType.Windows ) - { - Win64.SteamAPI_RunCallbacks(); - } - else if ( Config.Os == OsType.Posix ) - { - Posix.SteamAPI_RunCallbacks(); - } - else - { - throw new System.Exception( "this platform isn't supported" ); - } + Native.SteamAPI_RunCallbacks(); } static internal void RegisterCallback( IntPtr pCallback, int callback ) { - if ( Config.Os == OsType.Windows ) - { - 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" ); - } + Native.SteamAPI_RegisterCallback( pCallback, callback ); } static internal void UnregisterCallback( IntPtr pCallback ) { - if ( Config.Os == OsType.Windows ) - { - Win64.SteamAPI_UnregisterCallback( pCallback ); - } - else if ( Config.Os == OsType.Posix ) - { - Posix.SteamAPI_UnregisterCallback( pCallback ); - } - else - { - throw new System.Exception( "this platform isn't supported" ); - } + Native.SteamAPI_UnregisterCallback( pCallback ); } static internal void RegisterCallResult( IntPtr pCallback, SteamAPICall_t callback ) { - if ( Config.Os == OsType.Windows ) - { - 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" ); - } + Native.SteamAPI_RegisterCallResult( pCallback, callback ); } static internal void UnregisterCallResult( IntPtr pCallback, SteamAPICall_t callback ) { - if ( Config.Os == OsType.Windows ) - { - 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" ); - } + Native.SteamAPI_UnregisterCallResult( pCallback, callback ); } static internal void Shutdown() { - if ( Config.Os == OsType.Windows ) - { - Win64.SteamAPI_Shutdown(); - } - else if ( Config.Os == OsType.Posix ) - { - Posix.SteamAPI_Shutdown(); - } - else - { - throw new System.Exception( "this platform isn't supported" ); - } + Native.SteamAPI_Shutdown(); } static internal HSteamUser GetHSteamUser() { - if ( Config.Os == OsType.Windows ) - { - return Win64.SteamAPI_GetHSteamUser(); - } - else if ( Config.Os == OsType.Posix ) - { - return Posix.SteamAPI_GetHSteamUser(); - } - else - { - throw new System.Exception( "this platform isn't supported" ); - } + return Native.SteamAPI_GetHSteamUser(); } static internal HSteamPipe GetHSteamPipe() { - if ( Config.Os == OsType.Windows ) - { - return Win64.SteamAPI_GetHSteamPipe(); - } - else if ( Config.Os == OsType.Posix ) - { - return Posix.SteamAPI_GetHSteamPipe(); - } - else - { - throw new System.Exception( "this platform isn't supported" ); - } + return Native.SteamAPI_GetHSteamPipe(); } static internal bool RestartAppIfNecessary( uint unOwnAppID ) { - if ( Config.Os == OsType.Windows ) - { - 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" ); - } + return Native.SteamAPI_RestartAppIfNecessary( unOwnAppID ); } } diff --git a/Facepunch.Steamworks/Generated/SteamGameServer.cs b/Facepunch.Steamworks/Generated/SteamGameServer.cs index 26ee636..f9713c1 100644 --- a/Facepunch.Steamworks/Generated/SteamGameServer.cs +++ b/Facepunch.Steamworks/Generated/SteamGameServer.cs @@ -9,98 +9,39 @@ namespace Steamworks { 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(); - [DllImport( "steam_api64", EntryPoint = "SteamGameServer_Shutdown", CallingConvention = CallingConvention.Cdecl )] + [DllImport( Platform.LibraryName, EntryPoint = "SteamGameServer_Shutdown", CallingConvention = CallingConvention.Cdecl )] 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(); - [DllImport( "steam_api64", 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 )] + [DllImport( Platform.LibraryName, EntryPoint = "SteamGameServer_GetHSteamPipe", CallingConvention = CallingConvention.Cdecl )] public static extern HSteamPipe SteamGameServer_GetHSteamPipe(); } static internal void RunCallbacks() { - if ( Config.Os == OsType.Windows ) - { - Win64.SteamGameServer_RunCallbacks(); - } - else if ( Config.Os == OsType.Posix ) - { - Posix.SteamGameServer_RunCallbacks(); - } - else - { - throw new System.Exception( "this platform isn't supported" ); - } + Native.SteamGameServer_RunCallbacks(); } static internal void Shutdown() { - if ( Config.Os == OsType.Windows ) - { - Win64.SteamGameServer_Shutdown(); - } - else if ( Config.Os == OsType.Posix ) - { - Posix.SteamGameServer_Shutdown(); - } - else - { - throw new System.Exception( "this platform isn't supported" ); - } + Native.SteamGameServer_Shutdown(); } static internal HSteamUser GetHSteamUser() { - if ( Config.Os == OsType.Windows ) - { - return Win64.SteamGameServer_GetHSteamUser(); - } - else if ( Config.Os == OsType.Posix ) - { - return Posix.SteamGameServer_GetHSteamUser(); - } - else - { - throw new System.Exception( "this platform isn't supported" ); - } + return Native.SteamGameServer_GetHSteamUser(); } static internal HSteamPipe GetHSteamPipe() { - if ( Config.Os == OsType.Windows ) - { - return Win64.SteamGameServer_GetHSteamPipe(); - } - else if ( Config.Os == OsType.Posix ) - { - return Posix.SteamGameServer_GetHSteamPipe(); - } - else - { - throw new System.Exception( "this platform isn't supported" ); - } + return Native.SteamGameServer_GetHSteamPipe(); } } diff --git a/Facepunch.Steamworks/Generated/SteamInternal.cs b/Facepunch.Steamworks/Generated/SteamInternal.cs index c33b6e6..f9c15f0 100644 --- a/Facepunch.Steamworks/Generated/SteamInternal.cs +++ b/Facepunch.Steamworks/Generated/SteamInternal.cs @@ -9,100 +9,40 @@ namespace Steamworks { 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 )] 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 ); - [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 ); - [DllImport( "steam_api64", 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 )] + [DllImport( Platform.LibraryName, EntryPoint = "SteamInternal_CreateInterface", CallingConvention = CallingConvention.Cdecl )] 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 ) { - if ( Config.Os == OsType.Windows ) - { - 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" ); - } + return Native.SteamInternal_GameServer_Init( unIP, usPort, usGamePort, usQueryPort, eServerMode, pchVersionString ); } static internal IntPtr FindOrCreateUserInterface( int steamuser, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string versionname ) { - if ( Config.Os == OsType.Windows ) - { - 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" ); - } + return Native.SteamInternal_FindOrCreateUserInterface( steamuser, versionname ); } static internal IntPtr FindOrCreateGameServerInterface( int steamuser, [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string versionname ) { - if ( Config.Os == OsType.Windows ) - { - 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" ); - } + return Native.SteamInternal_FindOrCreateGameServerInterface( steamuser, versionname ); } static internal IntPtr CreateInterface( [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof( Utf8StringToNative ) )] string version ) { - if ( Config.Os == OsType.Windows ) - { - 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" ); - } + return Native.SteamInternal_CreateInterface( version ); } } diff --git a/Facepunch.Steamworks/Utility/Platform.cs b/Facepunch.Steamworks/Utility/Platform.cs index 7c26b9a..95448b0 100644 --- a/Facepunch.Steamworks/Utility/Platform.cs +++ b/Facepunch.Steamworks/Utility/Platform.cs @@ -11,8 +11,13 @@ internal static class Platform { #if PLATFORM_WIN64 public const int StructPlatformPackSize = 8; -#else + public const string LibraryName = "steam_api64"; +#elif PLATFORM_WIN32 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 public const int StructPackSize = 4; diff --git a/Generator/CodeWriter/GlobalFunctions.cs b/Generator/CodeWriter/GlobalFunctions.cs index c99085c..789bd15 100644 --- a/Generator/CodeWriter/GlobalFunctions.cs +++ b/Generator/CodeWriter/GlobalFunctions.cs @@ -27,20 +27,11 @@ public void GenerateGlobalFunctions( string startingWith, string filename ) { StartBlock( $"internal static class {startingWith}" ); { - StartBlock( $"internal static class Win64" ); + StartBlock( $"internal static class Native" ); { foreach ( var func in functions ) { - WriteMarshalledFunction( func, "steam_api64" ); - } - } - EndBlock(); - - StartBlock( $"internal static class Posix" ); - { - foreach ( var func in functions ) - { - WriteMarshalledFunction( func, "libsteam_api" ); + WriteMarshalledFunction( func ); } } EndBlock(); @@ -87,56 +78,28 @@ private void WriteGlobalFunction( string cname, SteamApiDefinition.MethodDef fun { var callargs = string.Join( ", ", args.Select( x => x.AsCallArgument() ) ); - StartBlock( "if ( Config.Os == OsType.Windows )" ); + if ( returnType.IsReturnedWeird ) { - - if ( returnType.IsReturnedWeird ) - { - 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 ) ); - } + WriteLine( $"var retVal = default( {returnType.TypeName} );" ); + WriteLine( $"Native.{func.Name}( ref retVal, {callargs} );" ); + WriteLine( $"{returnType.Return( "retVal" )}" ); } - Else( " if ( Config.Os == OsType.Posix )" ); + else if ( returnType.IsVoid ) { - if ( returnType.IsReturnedWeird ) - { - 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 ) ); - } + WriteLine( $"Native.{func.Name}( {callargs} );" ); } - Else(); + else { - WriteLine( "throw new System.Exception( \"this platform isn't supported\" );" ); + var v = $"Native.{func.Name}( {callargs} )"; + + WriteLine( returnType.Return( v ) ); } - EndBlock(); } EndBlock(); } - private void WriteMarshalledFunction( SteamApiDefinition.MethodDef func, string dllName ) + private void WriteMarshalledFunction( SteamApiDefinition.MethodDef func ) { var returnType = BaseType.Parse( func.ReturnType ); 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 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 ) WriteLine( returnType.ReturnAttribute );