diff --git a/Facepunch.Steamworks/Callbacks/SteamApiCallback.cs b/Facepunch.Steamworks/Callbacks/SteamApiCallback.cs new file mode 100644 index 0000000..8698692 --- /dev/null +++ b/Facepunch.Steamworks/Callbacks/SteamApiCallback.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using SteamNative; + +namespace Steamworks +{ + public struct SteamApiCallback where T : struct, ISteamCallback + { + public ulong CallHandle; + + public SteamApiCallback( ulong callbackHandle ) + { + CallHandle = callbackHandle; + } + + public bool IsComplete() + { + return Utils.IsCallComplete( CallHandle, out bool failed ); + } + + public T? GetResult() + { + return Utils.GetResult( CallHandle ); + } + } + + public interface ISteamCallback + { + int GetCallbackId(); + int GetStructSize(); + ISteamCallback Fill( IntPtr ptr, int size ); + } +} \ No newline at end of file diff --git a/Generator/CodeWriter/Types/BaseType.cs b/Generator/CodeWriter/Types/BaseType.cs index b3b6e8a..958c532 100644 --- a/Generator/CodeWriter/Types/BaseType.cs +++ b/Generator/CodeWriter/Types/BaseType.cs @@ -15,6 +15,8 @@ public static BaseType Parse( string type, string varname = null ) { if ( type == "SteamAPIWarningMessageHook_t" ) return new PointerType { NativeType = type, VarName = varname }; + if ( type == "SteamAPICall_t" ) return new SteamApiCallType { NativeType = type, VarName = varname }; + if ( type == "void" ) return new VoidType { NativeType = type, VarName = varname }; if ( type.Replace( " ", "" ) == "constchar*" ) return new ConstCharType { NativeType = type, VarName = varname }; if ( type == "char *" ) return new StringBuilderType { NativeType = type, VarName = varname }; @@ -42,6 +44,8 @@ public static BaseType Parse( string type, string varname = null ) public virtual string Return( string varname ) => $"return {varname};"; public virtual string ReturnAttribute => null; + public virtual string ReturnType => TypeName; + public virtual string Ref => !IsVector && NativeType.EndsWith( "*" ) ? "ref " : ""; public virtual bool IsVector => NativeType.EndsWith( "*" ) && (VarName.StartsWith( "pvec" ) || VarName.StartsWith( "pub" )); @@ -65,6 +69,14 @@ internal class StructType : BaseType public override string TypeName => StructName; } +internal class SteamApiCallType : BaseType +{ + public string CallResult; + public override string TypeName => "SteamAPICall_t"; + public override string Return( string varname ) => $"return new SteamApiCallback<{CallResult}>( {varname} );"; + public override string ReturnType => $"SteamApiCallback<{CallResult}>"; +} + internal class CSteamIdType : BaseType { public override bool IsReturnedWeird => true;