mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-04-26 23:09:37 +03:00
Callback update
This commit is contained in:
parent
8d605e99fa
commit
5da0690c5c
@ -81,13 +81,13 @@ namespace Facepunch.Steamworks
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Global callback type
|
/// Global callback type
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal void AddCallback<T, TSmall>( Action<T> Callback, int id )
|
internal void AddCallback<T, TSmall>( Action<T, bool> Callback, int id ) where T : new()
|
||||||
{
|
{
|
||||||
var callback = new Callback<T, TSmall>( native.api, IsGameServer, id, Callback );
|
var callback = new Callback<T, TSmall>( native.api, IsGameServer, id, Callback );
|
||||||
Disposables.Add( callback );
|
Disposables.Add( callback );
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void AddCallback<T>( Action<T> Callback, int id )
|
internal void AddCallback<T>( Action<T, bool> Callback, int id ) where T : new()
|
||||||
{
|
{
|
||||||
AddCallback<T, T>( Callback, id );
|
AddCallback<T, T>( Callback, id );
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ namespace Facepunch.Steamworks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onP2PConnectionRequest( P2PSessionRequest o )
|
private void onP2PConnectionRequest( P2PSessionRequest o, bool b )
|
||||||
{
|
{
|
||||||
if ( OnIncomingConnection != null )
|
if ( OnIncomingConnection != null )
|
||||||
{
|
{
|
||||||
@ -83,7 +83,7 @@ namespace Facepunch.Steamworks
|
|||||||
Max = 5
|
Max = 5
|
||||||
};
|
};
|
||||||
|
|
||||||
private void onP2PConnectionFailed( P2PSessionConnectFail o )
|
private void onP2PConnectionFailed( P2PSessionConnectFail o, bool b )
|
||||||
{
|
{
|
||||||
if ( OnConnectionFailed != null )
|
if ( OnConnectionFailed != null )
|
||||||
{
|
{
|
||||||
|
@ -37,13 +37,13 @@ namespace Facepunch.Steamworks
|
|||||||
OnItemInstalled = null;
|
OnItemInstalled = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onItemInstalled( ItemInstalled obj )
|
private void onItemInstalled( ItemInstalled obj, bool failed )
|
||||||
{
|
{
|
||||||
if ( OnItemInstalled != null )
|
if ( OnItemInstalled != null )
|
||||||
OnItemInstalled( obj.FileId );
|
OnItemInstalled( obj.FileId );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onDownloadResult( DownloadResult obj )
|
private void onDownloadResult( DownloadResult obj, bool failed )
|
||||||
{
|
{
|
||||||
if ( OnFileDownloaded != null )
|
if ( OnFileDownloaded != null )
|
||||||
OnFileDownloaded( obj.FileId, obj.Result );
|
OnFileDownloaded( obj.FileId, obj.Result );
|
||||||
|
@ -10,26 +10,29 @@ namespace Facepunch.Steamworks.Interop.VTable.This
|
|||||||
internal struct Callback
|
internal struct Callback
|
||||||
{
|
{
|
||||||
[UnmanagedFunctionPointer( CallingConvention.ThisCall )] public delegate void Result( IntPtr thisptr, IntPtr pvParam );
|
[UnmanagedFunctionPointer( CallingConvention.ThisCall )] public delegate void Result( IntPtr thisptr, IntPtr pvParam );
|
||||||
|
[UnmanagedFunctionPointer( CallingConvention.ThisCall )] public delegate void ResultBool( IntPtr thisptr, IntPtr pvParam, bool bIOFailure, SteamNative.SteamAPICall_t hSteamAPICall );
|
||||||
[UnmanagedFunctionPointer( CallingConvention.ThisCall )] public delegate int GetSize( IntPtr thisptr );
|
[UnmanagedFunctionPointer( CallingConvention.ThisCall )] public delegate int GetSize( IntPtr thisptr );
|
||||||
|
|
||||||
[MarshalAs(UnmanagedType.FunctionPtr)] public Result RunCallResult;
|
[MarshalAs(UnmanagedType.FunctionPtr)] public ResultBool RunCallResult;
|
||||||
[MarshalAs(UnmanagedType.FunctionPtr)] public Result RunCallback;
|
[MarshalAs(UnmanagedType.FunctionPtr)] public Result RunCallback;
|
||||||
[MarshalAs(UnmanagedType.FunctionPtr)] public GetSize GetCallbackSizeBytes;
|
[MarshalAs(UnmanagedType.FunctionPtr)] public GetSize GetCallbackSizeBytes;
|
||||||
|
|
||||||
internal static IntPtr Get( Action<IntPtr, IntPtr> onRunCallback, int size, Interop.Callback cb )
|
internal static IntPtr Get( Action<IntPtr, IntPtr, bool> onRunCallback, int size, Interop.Callback cb )
|
||||||
{
|
{
|
||||||
var ptr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback ) ) );
|
var ptr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback ) ) );
|
||||||
|
|
||||||
Callback.Result da = ( _, p ) => { onRunCallback( _, p ); };
|
Callback.Result da = ( _, p ) => { onRunCallback( _, p, false ); };
|
||||||
|
Callback.ResultBool db = ( _, p, iofailure, call ) => { onRunCallback( _, p, iofailure ); };
|
||||||
Callback.GetSize dc = ( _ ) => { return size; };
|
Callback.GetSize dc = ( _ ) => { return size; };
|
||||||
|
|
||||||
cb.AddHandle( GCHandle.Alloc( da ) );
|
cb.AddHandle( GCHandle.Alloc( da ) );
|
||||||
|
cb.AddHandle( GCHandle.Alloc( db ) );
|
||||||
cb.AddHandle( GCHandle.Alloc( dc ) );
|
cb.AddHandle( GCHandle.Alloc( dc ) );
|
||||||
|
|
||||||
var table = new Callback()
|
var table = new Callback()
|
||||||
{
|
{
|
||||||
RunCallback = da,
|
RunCallback = da,
|
||||||
RunCallResult = da,
|
RunCallResult = db,
|
||||||
GetCallbackSizeBytes = dc
|
GetCallbackSizeBytes = dc
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -48,20 +48,20 @@ namespace Facepunch.Steamworks.Interop
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal partial class Callback<T, TSmall> : Callback
|
internal partial class Callback<T, TSmall> : Callback where T : new()
|
||||||
{
|
{
|
||||||
private SteamNative.SteamApi api;
|
private SteamNative.SteamApi api;
|
||||||
|
|
||||||
public int CallbackId = 0;
|
public int CallbackId = 0;
|
||||||
public bool GameServer = false;
|
public bool GameServer = false;
|
||||||
public Action<T> Function;
|
public Action<T, bool> Function;
|
||||||
|
|
||||||
private IntPtr vTablePtr = IntPtr.Zero;
|
private IntPtr vTablePtr = IntPtr.Zero;
|
||||||
private GCHandle callbackPin;
|
private GCHandle callbackPin;
|
||||||
|
|
||||||
private readonly int m_size = Marshal.SizeOf(typeof(T));
|
private readonly int m_size = Marshal.SizeOf(typeof(T));
|
||||||
|
|
||||||
public Callback( SteamNative.SteamApi api, bool gameserver, int callbackid, Action<T> func )
|
public Callback( SteamNative.SteamApi api, bool gameserver, int callbackid, Action<T, bool> func )
|
||||||
{
|
{
|
||||||
this.api = api;
|
this.api = api;
|
||||||
GameServer = gameserver;
|
GameServer = gameserver;
|
||||||
@ -90,16 +90,22 @@ namespace Facepunch.Steamworks.Interop
|
|||||||
base.Dispose();
|
base.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnRunCallback( IntPtr thisObject, IntPtr ptr )
|
private void OnRunCallback( IntPtr thisObject, IntPtr ptr, bool failure )
|
||||||
{
|
{
|
||||||
if ( callbackPin == null ) throw new System.Exception( "Callback wasn't pinned!" );
|
if ( callbackPin == null ) throw new System.Exception( "Callback wasn't pinned!" );
|
||||||
if ( vTablePtr == IntPtr.Zero ) throw new System.Exception( "vTablePtr wasn't pinned!" );
|
if ( vTablePtr == IntPtr.Zero ) throw new System.Exception( "vTablePtr wasn't pinned!" );
|
||||||
if ( thisObject != IntPtr.Zero && thisObject != callbackPin.AddrOfPinnedObject() ) throw new System.Exception( "This wasn't valid!" );
|
if ( thisObject != IntPtr.Zero && thisObject != callbackPin.AddrOfPinnedObject() ) throw new System.Exception( "This wasn't valid! ("+ thisObject.ToInt64() + ") ( "+ callbackPin.AddrOfPinnedObject().ToInt64() + " )" );
|
||||||
|
|
||||||
if ( SteamNative.Platform.PackSmall && typeof(T) != typeof( TSmall ) ) throw new System.Exception( "Callback should use PackSmall" );
|
if ( SteamNative.Platform.PackSmall && typeof(T) != typeof( TSmall ) ) throw new System.Exception( "Callback should use PackSmall" );
|
||||||
|
|
||||||
|
if ( failure )
|
||||||
|
{
|
||||||
|
Function( new T(), failure );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
T data = (T) Marshal.PtrToStructure( ptr, typeof(T) );
|
T data = (T) Marshal.PtrToStructure( ptr, typeof(T) );
|
||||||
Function( data );
|
Function( data, failure );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ namespace Facepunch.Steamworks
|
|||||||
server.AddCallback<ValidateAuthTicketResponse>( OnAuthTicketValidate, ValidateAuthTicketResponse.CallbackId );
|
server.AddCallback<ValidateAuthTicketResponse>( OnAuthTicketValidate, ValidateAuthTicketResponse.CallbackId );
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnAuthTicketValidate( ValidateAuthTicketResponse data )
|
void OnAuthTicketValidate( ValidateAuthTicketResponse data, bool b )
|
||||||
{
|
{
|
||||||
if ( OnAuthChange != null )
|
if ( OnAuthChange != null )
|
||||||
OnAuthChange( data.SteamID, data.OwnerSteamID, (Status) data.AuthResponse );
|
OnAuthChange( data.SteamID, data.OwnerSteamID, (Status) data.AuthResponse );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user