From 01cf0f4cec514e76f17ac85f434530f5c75b3c34 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Mon, 8 May 2017 20:51:57 +0100 Subject: [PATCH] Achievement callback --- Facepunch.Steamworks/Client.cs | 2 + Facepunch.Steamworks/Client/Achievements.cs | 16 +- Facepunch.Steamworks/Client/Stats.cs | 2 - .../SteamNative/SteamNative.Structs.cs | 5936 +++++++++++++++++ Generator/CodeWriter/Struct.cs | 3 +- 5 files changed, 5955 insertions(+), 4 deletions(-) diff --git a/Facepunch.Steamworks/Client.cs b/Facepunch.Steamworks/Client.cs index 954a538..61ec9d5 100644 --- a/Facepunch.Steamworks/Client.cs +++ b/Facepunch.Steamworks/Client.cs @@ -84,6 +84,8 @@ namespace Facepunch.Steamworks Workshop.friends = Friends; + Stats.UpdateStats(); + // // Cache common, unchanging info // diff --git a/Facepunch.Steamworks/Client/Achievements.cs b/Facepunch.Steamworks/Client/Achievements.cs index ae43092..85b5aff 100644 --- a/Facepunch.Steamworks/Client/Achievements.cs +++ b/Facepunch.Steamworks/Client/Achievements.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using SteamNative; namespace Facepunch.Steamworks { @@ -11,10 +12,15 @@ namespace Facepunch.Steamworks public Achievement[] All { get; private set; } + public event Action OnUpdated; + internal Achievements( Client c ) { client = c; - Refresh(); + + All = new Achievement[0]; + + SteamNative.UserStatsReceived_t.RegisterCallback( c, UserStatsReceived ); } public void Refresh() @@ -29,6 +35,14 @@ namespace Facepunch.Steamworks client = null; } + private void UserStatsReceived( UserStatsReceived_t stats, bool isError ) + { + if ( isError ) return; + + Refresh(); + + OnUpdated?.Invoke(); + } } public class Achievement diff --git a/Facepunch.Steamworks/Client/Stats.cs b/Facepunch.Steamworks/Client/Stats.cs index 2a3bfc6..7c9e095 100644 --- a/Facepunch.Steamworks/Client/Stats.cs +++ b/Facepunch.Steamworks/Client/Stats.cs @@ -12,8 +12,6 @@ namespace Facepunch.Steamworks internal Stats( Client c ) { client = c; - - UpdateStats(); } public void UpdateStats() diff --git a/Facepunch.Steamworks/SteamNative/SteamNative.Structs.cs b/Facepunch.Steamworks/SteamNative/SteamNative.Structs.cs index ba7c44b..7c69973 100644 --- a/Facepunch.Steamworks/SteamNative/SteamNative.Structs.cs +++ b/Facepunch.Steamworks/SteamNative/SteamNative.Structs.cs @@ -960,6 +960,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( EncryptedAppTicketResponse_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( EncryptedAppTicketResponse_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -1420,6 +1532,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( StoreAuthURLResponse_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( StoreAuthURLResponse_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 4 )] @@ -2415,6 +2639,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( ClanOfficerListResponse_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( ClanOfficerListResponse_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 4 )] @@ -3483,6 +3819,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( JoinClanChatRoomCompletionResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( JoinClanChatRoomCompletionResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 4 )] @@ -3800,6 +4248,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( FriendsGetFollowerCount_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( FriendsGetFollowerCount_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 4 )] @@ -3971,6 +4531,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( FriendsIsFollowing_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( FriendsIsFollowing_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 4 )] @@ -4145,6 +4817,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( FriendsEnumerateFollowingList_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( FriendsEnumerateFollowingList_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -4318,6 +5102,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( SetPersonaNameResponse_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( SetPersonaNameResponse_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -4777,6 +5673,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( CheckFileSignature_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( CheckFileSignature_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -5595,6 +6603,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( LobbyEnter_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( LobbyEnter_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -6371,6 +7491,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( LobbyMatchList_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( LobbyMatchList_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -6688,6 +7920,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( LobbyCreated_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( LobbyCreated_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 4 )] @@ -7800,6 +9144,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( RemoteStorageFileShareResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( RemoteStorageFileShareResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -8119,6 +9575,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( RemoteStorageDeletePublishedFileResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( RemoteStorageDeletePublishedFileResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -8293,6 +9861,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( RemoteStorageEnumerateUserPublishedFilesResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( RemoteStorageEnumerateUserPublishedFilesResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -8459,6 +10139,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( RemoteStorageSubscribePublishedFileResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( RemoteStorageSubscribePublishedFileResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -8638,6 +10430,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( RemoteStorageEnumerateUserSubscribedFilesResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( RemoteStorageEnumerateUserSubscribedFilesResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -8804,6 +10708,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( RemoteStorageUnsubscribePublishedFileResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( RemoteStorageUnsubscribePublishedFileResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -8975,6 +10991,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( RemoteStorageUpdatePublishedFileResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( RemoteStorageUpdatePublishedFileResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -9155,6 +11283,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( RemoteStorageDownloadUGCResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( RemoteStorageDownloadUGCResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -9394,6 +11634,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( RemoteStorageGetPublishedFileDetailsResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( RemoteStorageGetPublishedFileDetailsResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -9579,6 +11931,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( RemoteStorageEnumerateWorkshopFilesResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( RemoteStorageEnumerateWorkshopFilesResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -9757,6 +12221,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( RemoteStorageGetPublishedItemVoteDetailsResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( RemoteStorageGetPublishedItemVoteDetailsResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -10367,6 +12943,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( RemoteStorageUpdateUserPublishedItemVoteResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( RemoteStorageUpdateUserPublishedItemVoteResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -10843,6 +13531,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( RemoteStorageSetUserPublishedFileActionResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( RemoteStorageSetUserPublishedFileActionResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -11025,6 +13825,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( RemoteStorageEnumeratePublishedFilesByUserActionResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( RemoteStorageEnumeratePublishedFilesByUserActionResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -11193,6 +14105,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( RemoteStoragePublishFileProgress_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( RemoteStoragePublishFileProgress_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -11507,6 +14531,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( RemoteStorageFileWriteAsyncComplete_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( RemoteStorageFileWriteAsyncComplete_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -11679,6 +14815,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( RemoteStorageFileReadAsyncComplete_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( RemoteStorageFileReadAsyncComplete_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 4 )] @@ -11892,6 +15140,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( UserStatsReceived_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( UserStatsReceived_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -12367,6 +15727,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( LeaderboardFindResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( LeaderboardFindResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -12536,6 +16008,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( LeaderboardScoresDownloaded_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( LeaderboardScoresDownloaded_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -12714,6 +16298,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( LeaderboardScoreUploaded_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( LeaderboardScoreUploaded_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -12880,6 +16576,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( NumberOfCurrentPlayers_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( NumberOfCurrentPlayers_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 4 )] @@ -13349,6 +17157,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( GlobalAchievementPercentagesReady_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( GlobalAchievementPercentagesReady_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -13515,6 +17435,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( LeaderboardUGCSet_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( LeaderboardUGCSet_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -13832,6 +17864,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( GlobalStatsReceived_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( GlobalStatsReceived_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -14455,6 +18599,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( FileDetailsResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( FileDetailsResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -17178,6 +21434,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( SteamUGCQueryCompleted_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( SteamUGCQueryCompleted_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -17499,6 +21867,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( CreateItemResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( CreateItemResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -17667,6 +22147,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( SubmitItemUpdateResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( SubmitItemUpdateResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -17989,6 +22581,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( UserFavoriteItemsListChanged_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( UserFavoriteItemsListChanged_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -18160,6 +22864,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( SetUserItemVoteResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( SetUserItemVoteResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -18341,6 +23157,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( GetUserItemVoteResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( GetUserItemVoteResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -18504,6 +23432,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( StartPlaytimeTrackingResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( StartPlaytimeTrackingResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -18667,6 +23707,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( StopPlaytimeTrackingResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( StopPlaytimeTrackingResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -19120,6 +24272,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( HTML_BrowserReady_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( HTML_BrowserReady_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -22523,6 +27787,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( SteamInventoryEligiblePromoItemDefIDs_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( SteamInventoryEligiblePromoItemDefIDs_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -24065,6 +29441,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( GSReputation_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( GSReputation_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 8 )] @@ -24228,6 +29716,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( AssociateWithClanResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( AssociateWithClanResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 4 )] @@ -24403,6 +30003,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( ComputeNewPlayerCompatibilityResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( ComputeNewPlayerCompatibilityResult_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 4 )] @@ -24569,6 +30281,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( GSStatsReceived_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( GSStatsReceived_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 4 )] @@ -24735,6 +30559,118 @@ namespace SteamNative return handle; } + + public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action CallbackFunction ) + { + var handle = new CallbackHandle(); + handle.steamworks = steamworks; + + // + // Create the functions we need for the vtable + // + if ( Facepunch.Steamworks.Config.UseThisCall ) + { + Callback.ThisCall.Result funcA = ( _, p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.ThisCall.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.ThisCall.GetSize funcC = ( _ ) => Marshal.SizeOf( typeof( GSStatsStored_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( _ ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + else + { + Callback.StdCall.Result funcA = ( p ) => { CallbackFunction( FromPointer( p ), false ); }; + Callback.StdCall.ResultWithInfo funcB = ( p, bIOFailure, hSteamAPICall ) => { CallbackFunction( FromPointer( p ), bIOFailure ); }; + Callback.StdCall.GetSize funcC = ( ) => Marshal.SizeOf( typeof( GSStatsStored_t ) ); + + // + // If this platform is PackSmall, use PackSmall versions of everything instead + // + if ( Platform.PackSmall ) + { + funcC = ( ) => Marshal.SizeOf( typeof( PackSmall ) ); + } + + // + // Allocate a handle to each function, so they don't get disposed + // + handle.FuncA = GCHandle.Alloc( funcA ); + handle.FuncB = GCHandle.Alloc( funcB ); + handle.FuncC = GCHandle.Alloc( funcC ); + + // + // Create the VTable by manually allocating the memory and copying across + // + handle.vTablePtr = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( Callback.VTable ) ) ); + var vTable = new Callback.VTable() + { + ResultA = Marshal.GetFunctionPointerForDelegate( funcA ), + ResultB = Marshal.GetFunctionPointerForDelegate( funcB ), + GetSize = Marshal.GetFunctionPointerForDelegate( funcC ), + }; + // + // The order of these functions are swapped on Windows + // + if ( Platform.IsWindows ) + { + vTable.ResultA = Marshal.GetFunctionPointerForDelegate( funcB ); + vTable.ResultB = Marshal.GetFunctionPointerForDelegate( funcA ); + } + Marshal.StructureToPtr( vTable, handle.vTablePtr, false ); + } + + // + // Create the callback object + // + var cb = new Callback(); + cb.vTablePtr = handle.vTablePtr; + cb.CallbackFlags = steamworks.IsGameServer ? (byte) SteamNative.Callback.Flags.GameServer : (byte) 0; + cb.CallbackId = CallbackId; + + // + // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native + // + handle.PinnedCallback = GCHandle.Alloc( cb, GCHandleType.Pinned ); + + // + // Register the callback with Steam + // + steamworks.native.api.SteamAPI_RegisterCallback( handle.PinnedCallback.AddrOfPinnedObject(), CallbackId ); + + steamworks.RegisterCallbackHandle( handle ); + } } [StructLayout( LayoutKind.Sequential, Pack = 4 )] diff --git a/Generator/CodeWriter/Struct.cs b/Generator/CodeWriter/Struct.cs index 571a18d..89ce93b 100644 --- a/Generator/CodeWriter/Struct.cs +++ b/Generator/CodeWriter/Struct.cs @@ -112,7 +112,8 @@ namespace Generator { CallResult( c ); } - else if ( !string.IsNullOrEmpty( c.CallbackId ) ) + + if ( !string.IsNullOrEmpty( c.CallbackId ) ) { Callback( c ); }