SteamApiCallback

This commit is contained in:
Garry Newman 2019-04-13 18:44:37 +01:00
parent 06446a8bc0
commit ede67d51cd
2 changed files with 48 additions and 0 deletions

View File

@ -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<T> 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<T>( CallHandle );
}
}
public interface ISteamCallback
{
int GetCallbackId();
int GetStructSize();
ISteamCallback Fill( IntPtr ptr, int size );
}
}

View File

@ -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;