MacOs loading

This commit is contained in:
Garry Newman 2019-04-29 15:47:23 +01:00
parent e68dc15454
commit 74ef28b9fc
4 changed files with 332 additions and 31 deletions

View File

@ -43,56 +43,201 @@ internal static class Win64
[return: MarshalAs( UnmanagedType.I1 )]
public static extern bool SteamAPI_RestartAppIfNecessary( uint unOwnAppID );
}
internal static class MacOs
{
[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 )]
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.MacOs )
{
return MacOs.SteamAPI_Init();
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
}
static internal void RunCallbacks()
{
if ( Config.Os == OsType.Windows )
{
Win64.SteamAPI_RunCallbacks();
}
else if ( Config.Os == OsType.MacOs )
{
MacOs.SteamAPI_RunCallbacks();
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
}
static internal void RegisterCallback( IntPtr pCallback, int callback )
{
if ( Config.Os == OsType.Windows )
{
Win64.SteamAPI_RegisterCallback( pCallback, callback );
}
else if ( Config.Os == OsType.MacOs )
{
MacOs.SteamAPI_RegisterCallback( pCallback, callback );
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
}
static internal void UnregisterCallback( IntPtr pCallback )
{
if ( Config.Os == OsType.Windows )
{
Win64.SteamAPI_UnregisterCallback( pCallback );
}
else if ( Config.Os == OsType.MacOs )
{
MacOs.SteamAPI_UnregisterCallback( pCallback );
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
}
static internal void RegisterCallResult( IntPtr pCallback, SteamAPICall_t callback )
{
if ( Config.Os == OsType.Windows )
{
Win64.SteamAPI_RegisterCallResult( pCallback, callback );
}
else if ( Config.Os == OsType.MacOs )
{
MacOs.SteamAPI_RegisterCallResult( pCallback, callback );
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
}
static internal void UnregisterCallResult( IntPtr pCallback, SteamAPICall_t callback )
{
if ( Config.Os == OsType.Windows )
{
Win64.SteamAPI_UnregisterCallResult( pCallback, callback );
}
else if ( Config.Os == OsType.MacOs )
{
MacOs.SteamAPI_UnregisterCallResult( pCallback, callback );
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
}
static internal void Shutdown()
{
if ( Config.Os == OsType.Windows )
{
Win64.SteamAPI_Shutdown();
}
else if ( Config.Os == OsType.MacOs )
{
MacOs.SteamAPI_Shutdown();
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
}
static internal HSteamUser GetHSteamUser()
{
if ( Config.Os == OsType.Windows )
{
return Win64.SteamAPI_GetHSteamUser();
}
else if ( Config.Os == OsType.MacOs )
{
return MacOs.SteamAPI_GetHSteamUser();
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
}
static internal HSteamPipe GetHSteamPipe()
{
if ( Config.Os == OsType.Windows )
{
return Win64.SteamAPI_GetHSteamPipe();
}
else if ( Config.Os == OsType.MacOs )
{
return MacOs.SteamAPI_GetHSteamPipe();
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
}
static internal bool RestartAppIfNecessary( uint unOwnAppID )
{
if ( Config.Os == OsType.Windows )
{
return Win64.SteamAPI_RestartAppIfNecessary( unOwnAppID );
}
else if ( Config.Os == OsType.MacOs )
{
return MacOs.SteamAPI_RestartAppIfNecessary( unOwnAppID );
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
}
}
}

View File

@ -23,26 +23,85 @@ internal static class Win64
[DllImport( "steam_api64", EntryPoint = "SteamGameServer_GetHSteamPipe", CallingConvention = CallingConvention.Cdecl )]
public static extern HSteamPipe SteamGameServer_GetHSteamPipe();
}
internal static class MacOs
{
[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();
}
static internal void RunCallbacks()
{
if ( Config.Os == OsType.Windows )
{
Win64.SteamGameServer_RunCallbacks();
}
else if ( Config.Os == OsType.MacOs )
{
MacOs.SteamGameServer_RunCallbacks();
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
}
static internal void Shutdown()
{
if ( Config.Os == OsType.Windows )
{
Win64.SteamGameServer_Shutdown();
}
else if ( Config.Os == OsType.MacOs )
{
MacOs.SteamGameServer_Shutdown();
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
}
static internal HSteamUser GetHSteamUser()
{
if ( Config.Os == OsType.Windows )
{
return Win64.SteamGameServer_GetHSteamUser();
}
else if ( Config.Os == OsType.MacOs )
{
return MacOs.SteamGameServer_GetHSteamUser();
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
}
static internal HSteamPipe GetHSteamPipe()
{
if ( Config.Os == OsType.Windows )
{
return Win64.SteamGameServer_GetHSteamPipe();
}
else if ( Config.Os == OsType.MacOs )
{
return MacOs.SteamGameServer_GetHSteamPipe();
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
}
}
}

View File

@ -24,26 +24,86 @@ internal static class Win64
[DllImport( "steam_api64", EntryPoint = "SteamInternal_CreateInterface", CallingConvention = CallingConvention.Cdecl )]
public static extern IntPtr SteamInternal_CreateInterface( string version );
}
internal static class MacOs
{
[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, string pchVersionString );
[DllImport( "libsteam_api", EntryPoint = "SteamInternal_FindOrCreateUserInterface", CallingConvention = CallingConvention.Cdecl )]
public static extern IntPtr SteamInternal_FindOrCreateUserInterface( int steamuser, string versionname );
[DllImport( "libsteam_api", EntryPoint = "SteamInternal_FindOrCreateGameServerInterface", CallingConvention = CallingConvention.Cdecl )]
public static extern IntPtr SteamInternal_FindOrCreateGameServerInterface( int steamuser, string versionname );
[DllImport( "libsteam_api", EntryPoint = "SteamInternal_CreateInterface", CallingConvention = CallingConvention.Cdecl )]
public static extern IntPtr SteamInternal_CreateInterface( string version );
}
static internal bool GameServer_Init( uint unIP, ushort usPort, ushort usGamePort, ushort usQueryPort, int eServerMode, string pchVersionString )
{
if ( Config.Os == OsType.Windows )
{
return Win64.SteamInternal_GameServer_Init( unIP, usPort, usGamePort, usQueryPort, eServerMode, pchVersionString );
}
else if ( Config.Os == OsType.MacOs )
{
return MacOs.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, string versionname )
{
if ( Config.Os == OsType.Windows )
{
return Win64.SteamInternal_FindOrCreateUserInterface( steamuser, versionname );
}
else if ( Config.Os == OsType.MacOs )
{
return MacOs.SteamInternal_FindOrCreateUserInterface( steamuser, versionname );
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
}
static internal IntPtr FindOrCreateGameServerInterface( int steamuser, string versionname )
{
if ( Config.Os == OsType.Windows )
{
return Win64.SteamInternal_FindOrCreateGameServerInterface( steamuser, versionname );
}
else if ( Config.Os == OsType.MacOs )
{
return MacOs.SteamInternal_FindOrCreateGameServerInterface( steamuser, versionname );
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
}
static internal IntPtr CreateInterface( string version )
{
if ( Config.Os == OsType.Windows )
{
return Win64.SteamInternal_CreateInterface( version );
}
else if ( Config.Os == OsType.MacOs )
{
return MacOs.SteamInternal_CreateInterface( version );
}
else
{
throw new System.Exception( "this platform isn't supported" );
}
}
}
}

View File

@ -36,6 +36,15 @@ public void GenerateGlobalFunctions( string startingWith, string filename )
}
EndBlock();
StartBlock( $"internal static class MacOs" );
{
foreach ( var func in functions )
{
WriteMarshalledFunction( func, "libsteam_api" );
}
}
EndBlock();
foreach ( var func in functions )
{
WriteGlobalFunction( startingWith, func );
@ -78,6 +87,9 @@ 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 )
{
WriteLine( $"var retVal = default( {returnType.TypeName} );" );
@ -95,6 +107,31 @@ private void WriteGlobalFunction( string cname, SteamApiDefinition.MethodDef fun
WriteLine( returnType.Return( v ) );
}
}
Else( " if ( Config.Os == OsType.MacOs )" );
{
if ( returnType.IsReturnedWeird )
{
WriteLine( $"var retVal = default( {returnType.TypeName} );" );
WriteLine( $"MacOs.{func.Name}( ref retVal, {callargs} );" );
WriteLine( $"{returnType.Return( "retVal" )}" );
}
else if ( returnType.IsVoid )
{
WriteLine( $"MacOs.{func.Name}( {callargs} );" );
}
else
{
var v = $"MacOs.{func.Name}( {callargs} )";
WriteLine( returnType.Return( v ) );
}
}
Else();
{
WriteLine( "throw new System.Exception( \"this platform isn't supported\" );" );
}
EndBlock();
}
EndBlock();
}