From 599ca7cbe1311c17c47fe26557f66b6cc0a8e123 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Wed, 12 Feb 2020 15:27:30 +0000 Subject: [PATCH] Interface generation fixes --- Facepunch.Steamworks/Structs/SteamNetworking.cs | 17 ----------------- Generator/Cleanup.cs | 10 ++++++++++ Generator/CodeWriter/ClassVTable.cs | 15 +++++++-------- Generator/CodeWriter/Enums.cs | 2 +- Generator/CodeWriter/Types.cs | 8 ++++++-- Generator/CodeWriter/Types/BaseType.cs | 12 ++++++++++-- Generator/SteamApiDefinition.cs | 1 + 7 files changed, 35 insertions(+), 30 deletions(-) diff --git a/Facepunch.Steamworks/Structs/SteamNetworking.cs b/Facepunch.Steamworks/Structs/SteamNetworking.cs index 3b8f786..cc729a6 100644 --- a/Facepunch.Steamworks/Structs/SteamNetworking.cs +++ b/Facepunch.Steamworks/Structs/SteamNetworking.cs @@ -7,23 +7,6 @@ namespace Steamworks.Data { delegate void FSteamNetworkingSocketsDebugOutput (DebugOutputType nType, string pszMsg ); - public struct SteamNetworkingPOPID - { - public uint Value; - - public static implicit operator SteamNetworkingPOPID( uint value ) - { - return new SteamNetworkingPOPID { Value = value }; - } - - public static implicit operator uint( SteamNetworkingPOPID value ) - { - return value.Value; - } - - public override string ToString() => Value.ToString(); - } - [StructLayout( LayoutKind.Sequential )] public struct SteamNetworkingQuickConnectionStatus { diff --git a/Generator/Cleanup.cs b/Generator/Cleanup.cs index cb5eb06..387b519 100644 --- a/Generator/Cleanup.cs +++ b/Generator/Cleanup.cs @@ -13,6 +13,8 @@ public static class Cleanup type = type.Replace( "class ", "" ); type = type.Replace( "struct ", "" ); + type = type.Replace( "unsigned long long", "uint64" ); + type = type.Replace( "CSteamID", "SteamId" ); type = type.Replace( "CGameID", "GameId" ); type = type.Replace( "PersonaState", "FriendState" ); @@ -47,6 +49,7 @@ public static class Cleanup type = type.Replace( "InputAnalogActionData_t", "AnalogState" ); type = type.Replace( "InputMotionData_t", "MotionState" ); type = type.Replace( "MatchMakingKeyValuePair_t", "MatchMakingKeyValuePair" ); + type = type.Replace( "ISteamNetworkingMessage", "SteamNetworkingMessage_t" ); return type; } @@ -61,6 +64,13 @@ public static class Cleanup if ( type == "DigitalState" ) return false; if ( type == "MotionState" ) return false; if ( type == "MatchMakingKeyValuePair" ) return false; + if ( type == "Connection" ) return false; + if ( type == "Socket" ) return false; + if ( type == "SteamNetworkingErrMsg" ) return false; + if ( type == "SteamNetworkingMicroseconds" ) return false; + if ( type == "FSteamNetworkingSocketsDebugOutput" ) return false; + if ( type == "SteamNetworkingMessage_t" ) return false; + if ( type == "SteamDatagramErrMsg" ) return false; return true; } diff --git a/Generator/CodeWriter/ClassVTable.cs b/Generator/CodeWriter/ClassVTable.cs index bb5e8fb..d776d3b 100644 --- a/Generator/CodeWriter/ClassVTable.cs +++ b/Generator/CodeWriter/ClassVTable.cs @@ -53,7 +53,7 @@ namespace Generator } private void WriteFunction( SteamApiDefinition.Interface iface, SteamApiDefinition.Interface.Method func ) { - var returnType = BaseType.Parse( func.ReturnType, null ); + var returnType = BaseType.Parse( func.ReturnType, null, func.CallResult ); returnType.Func = func.Name; if ( func.Params == null ) @@ -70,7 +70,7 @@ namespace Generator { if ( args[i] is StringType ) { - if ( args[i + 1] is IntType || args[i + 1] is UIntType ) + if ( args[i + 1] is IntType || args[i + 1] is UIntType || args[i + 1] is UIntPtrType ) { if ( args[i + 1].Ref == string.Empty ) { @@ -87,12 +87,11 @@ namespace Generator var argstr = string.Join( ", ", args.Where( x => !x.ShouldSkipAsArgument ).Select( x => x.AsArgument() ) ); ; var delegateargstr = string.Join( ", ", args.Select( x => x.AsNativeArgument() ) ); - //if ( returnType is SteamApiCallType sap ) - // { - // sap.CallResult = func.CallResult; - - // argstr = string.Join( ", ", args.Select( x => x.AsArgument().Replace( "ref ", " /* ref */ " ) ) ); - // } + if ( returnType is SteamApiCallType sap ) + { + sap.CallResult = func.CallResult; + argstr = string.Join( ", ", args.Select( x => x.AsArgument().Replace( "ref ", " /* ref */ " ) ) ); + } WriteLine( $"#region FunctionMeta" ); diff --git a/Generator/CodeWriter/Enums.cs b/Generator/CodeWriter/Enums.cs index cc5c6be..1fbc975 100644 --- a/Generator/CodeWriter/Enums.cs +++ b/Generator/CodeWriter/Enums.cs @@ -30,7 +30,7 @@ namespace Generator if ( !Cleanup.ShouldCreate( name ) ) continue; - StartBlock( $"{Cleanup.Expose( name )} enum {name} : int" ); + StartBlock( $"{Cleanup.Expose( name )} enum {name} : uint" ); { // // If all the enum values start with the same diff --git a/Generator/CodeWriter/Types.cs b/Generator/CodeWriter/Types.cs index a4f2b1b..f9319d5 100644 --- a/Generator/CodeWriter/Types.cs +++ b/Generator/CodeWriter/Types.cs @@ -37,7 +37,10 @@ namespace Generator { foreach ( var o in def.typedefs.Where( x => !x.Name.Contains( "::" ) ) ) { - var typeName = Cleanup.ConvertType( o.Name ); + if ( !Cleanup.ShouldCreate( o.Name ) ) + continue; + + var typeName = Cleanup.ConvertType( o.Name ); if ( !Cleanup.ShouldCreate( typeName ) ) continue; @@ -50,7 +53,8 @@ namespace Generator StartBlock( $"{Cleanup.Expose( typeName )} struct {typeName} : IEquatable<{typeName}>, IComparable<{typeName}>" ); { - WriteLine( $"public {ToManagedType( o.Type )} Value;" ); + WriteLine( $"// Name: {o.Name}, Type: {o.Type}" ); + WriteLine( $"public {ToManagedType( o.Type )} Value;" ); WriteLine(); WriteLine( $"public static implicit operator {typeName}( {ToManagedType( o.Type )} value ) => new {typeName}(){{ Value = value }};" ); WriteLine( $"public static implicit operator {ToManagedType( o.Type )}( {typeName} value ) => value.Value;" ); diff --git a/Generator/CodeWriter/Types/BaseType.cs b/Generator/CodeWriter/Types/BaseType.cs index 3843d57..991941e 100644 --- a/Generator/CodeWriter/Types/BaseType.cs +++ b/Generator/CodeWriter/Types/BaseType.cs @@ -41,8 +41,11 @@ internal class BaseType if ( basicType == "unsigned short" ) return new UInt16Type { NativeType = type, VarName = varname }; if ( basicType == "SteamId" ) return new CSteamIdType { NativeType = type, VarName = varname }; + + if ( basicType == "size_t" ) return new UIntPtrType{ NativeType = type, VarName = varname }; + // DANGER DANGER Danger - if ( basicType == "size_t" ) return new ULongType { NativeType = type, VarName = varname }; + if ( basicType == "intptr_t" ) return new LongType { NativeType = type, VarName = varname }; if ( basicType == "ptrdiff_t" ) return new LongType { NativeType = type, VarName = varname }; @@ -68,7 +71,7 @@ internal class BaseType public virtual bool ShouldSkipAsArgument => false; public virtual string AsNativeArgument() => AsArgument(); - public virtual string AsArgument() => IsVector ? $"[In,Out] {Ref}{TypeName.Trim( '*', ' ' )}[] {VarName}" : $"{Ref}{TypeName.Trim( '*', ' ' )} {VarName}"; + public virtual string AsArgument() => IsVector ? $"[In,Out] {Ref}{TypeName.Trim( '*', ' ', '&' )}[] {VarName}" : $"{Ref}{TypeName.Trim( '*', ' ', '&' )} {VarName}"; public virtual string AsCallArgument() => $"{Ref}{VarName}"; public virtual string Return( string varname ) => $"return {varname};"; @@ -217,6 +220,11 @@ internal class UInt16Type : BaseType public override string TypeName => $"ushort"; } +internal class UIntPtrType : BaseType +{ + public override string TypeName => $"UIntPtr"; +} + internal class PointerType : BaseType { public override string TypeName => $"IntPtr"; diff --git a/Generator/SteamApiDefinition.cs b/Generator/SteamApiDefinition.cs index 2580407..1d8db23 100644 --- a/Generator/SteamApiDefinition.cs +++ b/Generator/SteamApiDefinition.cs @@ -20,6 +20,7 @@ namespace Generator public class Method { public string ReturnType { get; set; } + public string CallResult { get; set; } public class Param {