From 303da3753dabcad734587d5b72584b95be8de200 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Fri, 9 Jun 2017 10:30:43 +0100 Subject: [PATCH] Microtransaction callback (requested, but untested) --- Facepunch.Steamworks/Client.cs | 10 +++++ .../Client/MicroTransactions.cs | 44 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 Facepunch.Steamworks/Client/MicroTransactions.cs diff --git a/Facepunch.Steamworks/Client.cs b/Facepunch.Steamworks/Client.cs index d5694ef..9b49fbc 100644 --- a/Facepunch.Steamworks/Client.cs +++ b/Facepunch.Steamworks/Client.cs @@ -58,6 +58,7 @@ public partial class Client : BaseSteamworks public App App { get; private set; } public Achievements Achievements { get; private set; } public Stats Stats { get; private set; } + public MicroTransactions MicroTransactions { get; private set; } public Client( uint appId ) { @@ -87,6 +88,7 @@ public Client( uint appId ) App = new App( this ); Stats = new Stats( this ); Achievements = new Achievements( this ); + MicroTransactions = new MicroTransactions( this ); Workshop.friends = Friends; @@ -105,6 +107,8 @@ public Client( uint appId ) CurrentLanguage = native.apps.GetCurrentGameLanguage(); AvailableLanguages = native.apps.GetAvailableGameLanguages().Split( new[] {';'}, StringSplitOptions.RemoveEmptyEntries ); // TODO: Assumed colon separated + + // // Run update, first call does some initialization // @@ -168,6 +172,12 @@ public override void Dispose() Achievements = null; } + if ( MicroTransactions != null ) + { + MicroTransactions.Dispose(); + MicroTransactions = null; + } + if ( Instance == this ) { Instance = null; diff --git a/Facepunch.Steamworks/Client/MicroTransactions.cs b/Facepunch.Steamworks/Client/MicroTransactions.cs new file mode 100644 index 0000000..d2176c8 --- /dev/null +++ b/Facepunch.Steamworks/Client/MicroTransactions.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using SteamNative; + +namespace Facepunch.Steamworks +{ + public class MicroTransactions : IDisposable + { + internal Client client; + + public delegate void AuthorizationResponse( bool authorized, int appId, ulong orderId ); + + /// + /// Called on the MicroTxnAuthorizationResponse_t event + /// + public event AuthorizationResponse OnAuthorizationResponse; + + internal MicroTransactions( Client c ) + { + client = c; + + SteamNative.MicroTxnAuthorizationResponse_t.RegisterCallback( client, onMicroTxnAuthorizationResponse ); + } + + private void onMicroTxnAuthorizationResponse( MicroTxnAuthorizationResponse_t arg1, bool arg2 ) + { + if ( OnAuthorizationResponse != null ) + { + OnAuthorizationResponse( arg1.Authorized == 1, (int) arg1.AppID, arg1.OrderID ); + } + + throw new NotImplementedException(); + } + + public void Dispose() + { + client = null; + } + } +}