mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-24 13:45:37 +03:00
SteamApiCallback
This commit is contained in:
parent
06446a8bc0
commit
ede67d51cd
36
Facepunch.Steamworks/Callbacks/SteamApiCallback.cs
Normal file
36
Facepunch.Steamworks/Callbacks/SteamApiCallback.cs
Normal 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 );
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user