From 17b84c4f589ade46bffbcd0580cefafcc81df245 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Sat, 29 Oct 2016 21:05:48 +0100 Subject: [PATCH] Parse defines --- Facepunch.Steamworks/Interop/Native.cs | 28 ++++---- .../SteamNative/SteamNative.Constants.cs | 27 ++++++++ Generator/CodeParser/CodeParser.cs | 11 ++++ Generator/CodeWriter/Constants.cs | 64 ++++--------------- Generator/CodeWriter/Types.cs | 58 +++++++++++++++-- Generator/SteamApiDefinition.cs | 1 + 6 files changed, 118 insertions(+), 71 deletions(-) diff --git a/Facepunch.Steamworks/Interop/Native.cs b/Facepunch.Steamworks/Interop/Native.cs index 751a8a4..11d38ee 100644 --- a/Facepunch.Steamworks/Interop/Native.cs +++ b/Facepunch.Steamworks/Interop/Native.cs @@ -91,20 +91,20 @@ public void FillInterfaces( int hpipe, int huser ) client = new SteamNative.SteamClient( clientPtr ); - user = client.GetISteamUser( huser, hpipe, "SteamUser019" ); - utils = client.GetISteamUtils( hpipe, "SteamUtils008" ); - networking = client.GetISteamNetworking( huser, hpipe, "SteamNetworking005" ); - gameServerStats = client.GetISteamGameServerStats( huser, hpipe, "SteamGameServerStats001" ); - http = client.GetISteamHTTP( huser, hpipe, "STEAMHTTP_INTERFACE_VERSION002" ); - inventory = client.GetISteamInventory( huser, hpipe, "STEAMINVENTORY_INTERFACE_V001" ); - ugc = client.GetISteamUGC( huser, hpipe, "STEAMUGC_INTERFACE_VERSION009" ); - apps = client.GetISteamApps( huser, hpipe, "STEAMAPPS_INTERFACE_VERSION008" ); - gameServer = client.GetISteamGameServer( huser, hpipe, "SteamGameServer012" ); - friends = client.GetISteamFriends( huser, hpipe, "SteamFriends015" ); - servers = client.GetISteamMatchmakingServers( huser, hpipe, "SteamMatchMakingServers002" ); - userstats = client.GetISteamUserStats( huser, hpipe, "STEAMUSERSTATS_INTERFACE_VERSION011" ); - screenshots = client.GetISteamScreenshots( huser, hpipe, "STEAMSCREENSHOTS_INTERFACE_VERSION003" ); - remoteStorage = client.GetISteamRemoteStorage( huser, hpipe, "STEAMREMOTESTORAGE_INTERFACE_VERSION014" ); + user = client.GetISteamUser( huser, hpipe, SteamNative.Defines.STEAMUSER_INTERFACE_VERSION ); + utils = client.GetISteamUtils( hpipe, SteamNative.Defines.STEAMUTILS_INTERFACE_VERSION ); + networking = client.GetISteamNetworking( huser, hpipe, SteamNative.Defines.STEAMNETWORKING_INTERFACE_VERSION ); + gameServerStats = client.GetISteamGameServerStats( huser, hpipe, SteamNative.Defines.STEAMGAMESERVERSTATS_INTERFACE_VERSION ); + http = client.GetISteamHTTP( huser, hpipe, SteamNative.Defines.STEAMHTTP_INTERFACE_VERSION ); + inventory = client.GetISteamInventory( huser, hpipe, SteamNative.Defines.STEAMINVENTORY_INTERFACE_VERSION ); + ugc = client.GetISteamUGC( huser, hpipe, SteamNative.Defines.STEAMUGC_INTERFACE_VERSION ); + apps = client.GetISteamApps( huser, hpipe, SteamNative.Defines.STEAMAPPS_INTERFACE_VERSION ); + gameServer = client.GetISteamGameServer( huser, hpipe, SteamNative.Defines.STEAMGAMESERVER_INTERFACE_VERSION ); + friends = client.GetISteamFriends( huser, hpipe, SteamNative.Defines.STEAMFRIENDS_INTERFACE_VERSION ); + servers = client.GetISteamMatchmakingServers( huser, hpipe, SteamNative.Defines.STEAMMATCHMAKINGSERVERS_INTERFACE_VERSION ); + userstats = client.GetISteamUserStats( huser, hpipe, SteamNative.Defines.STEAMUSERSTATS_INTERFACE_VERSION ); + screenshots = client.GetISteamScreenshots( huser, hpipe, SteamNative.Defines.STEAMSCREENSHOTS_INTERFACE_VERSION ); + remoteStorage = client.GetISteamRemoteStorage( huser, hpipe, SteamNative.Defines.STEAMREMOTESTORAGE_INTERFACE_VERSION ); } public void Dispose() diff --git a/Facepunch.Steamworks/SteamNative/SteamNative.Constants.cs b/Facepunch.Steamworks/SteamNative/SteamNative.Constants.cs index f1045c8..fd43c23 100644 --- a/Facepunch.Steamworks/SteamNative/SteamNative.Constants.cs +++ b/Facepunch.Steamworks/SteamNative/SteamNative.Constants.cs @@ -53,4 +53,31 @@ public static class CallbackIdentifiers public const int ClientInventory = 4700; public const int ClientBluetoothManager = 4800; } + public static class Defines + { + public const string STEAMAPPLIST_INTERFACE_VERSION = "STEAMAPPLIST_INTERFACE_VERSION001"; + public const string STEAMAPPS_INTERFACE_VERSION = "STEAMAPPS_INTERFACE_VERSION008"; + public const string STEAMAPPTICKET_INTERFACE_VERSION = "STEAMAPPTICKET_INTERFACE_VERSION001"; + public const string STEAMCONTROLLER_INTERFACE_VERSION = "SteamController004"; + public const string STEAMFRIENDS_INTERFACE_VERSION = "SteamFriends015"; + public const string STEAMGAMECOORDINATOR_INTERFACE_VERSION = "SteamGameCoordinator001"; + public const string STEAMGAMESERVER_INTERFACE_VERSION = "SteamGameServer012"; + public const string STEAMGAMESERVERSTATS_INTERFACE_VERSION = "SteamGameServerStats001"; + public const string STEAMHTMLSURFACE_INTERFACE_VERSION = "STEAMHTMLSURFACE_INTERFACE_VERSION_003"; + public const string STEAMHTTP_INTERFACE_VERSION = "STEAMHTTP_INTERFACE_VERSION002"; + public const string STEAMINVENTORY_INTERFACE_VERSION = "STEAMINVENTORY_INTERFACE_V001"; + public const string STEAMMATCHMAKING_INTERFACE_VERSION = "SteamMatchMaking009"; + public const string STEAMMATCHMAKINGSERVERS_INTERFACE_VERSION = "SteamMatchMakingServers002"; + public const string STEAMMUSIC_INTERFACE_VERSION = "STEAMMUSIC_INTERFACE_VERSION001"; + public const string STEAMMUSICREMOTE_INTERFACE_VERSION = "STEAMMUSICREMOTE_INTERFACE_VERSION001"; + public const string STEAMNETWORKING_INTERFACE_VERSION = "SteamNetworking005"; + public const string STEAMREMOTESTORAGE_INTERFACE_VERSION = "STEAMREMOTESTORAGE_INTERFACE_VERSION014"; + public const string STEAMSCREENSHOTS_INTERFACE_VERSION = "STEAMSCREENSHOTS_INTERFACE_VERSION003"; + public const string STEAMUGC_INTERFACE_VERSION = "STEAMUGC_INTERFACE_VERSION009"; + public const string STEAMUNIFIEDMESSAGES_INTERFACE_VERSION = "STEAMUNIFIEDMESSAGES_INTERFACE_VERSION001"; + public const string STEAMUSER_INTERFACE_VERSION = "SteamUser019"; + public const string STEAMUSERSTATS_INTERFACE_VERSION = "STEAMUSERSTATS_INTERFACE_VERSION011"; + public const string STEAMUTILS_INTERFACE_VERSION = "SteamUtils008"; + public const string STEAMVIDEO_INTERFACE_VERSION = "STEAMVIDEO_INTERFACE_V001"; + } } diff --git a/Generator/CodeParser/CodeParser.cs b/Generator/CodeParser/CodeParser.cs index c82a287..c66c9b6 100644 --- a/Generator/CodeParser/CodeParser.cs +++ b/Generator/CodeParser/CodeParser.cs @@ -54,6 +54,17 @@ internal void ExtendDefinition( SteamApiDefinition def ) } } + def.Defines = new Dictionary(); + { + var r = new Regex( @"#define ([a-zA-Z_]+) ""(.+)""" ); + var ma = r.Matches( Content ); + + foreach ( Match m in ma ) + { + def.Defines.Add( m.Groups[1].Value.Replace( "Callbacks", "" ), m.Groups[2].Value ); + } + } + } } } diff --git a/Generator/CodeWriter/Constants.cs b/Generator/CodeWriter/Constants.cs index 16f9abf..306d2db 100644 --- a/Generator/CodeWriter/Constants.cs +++ b/Generator/CodeWriter/Constants.cs @@ -8,59 +8,21 @@ namespace Generator { public partial class CodeWriter { - // - // Don't give a fuck about these types - // - public readonly static string[] SkipTypes = new string[] + private void Constants() { - "ValvePackingSentinel_t", - "SteamAPIWarningMessageHook_t", - "Salt_t", - "SteamAPI_CheckCallbackRegistered_t", - "compile_time_assert_type" - }; - - // - // Native types and function defs - // - public readonly static string[] SkipTypesStartingWith = new string[] - { - "uint", - "int", - "ulint", - "lint", - "PFN" - }; - - private void Types() - { - foreach ( var o in def.typedefs.Where( x => !x.Name.Contains( "::" ) ) ) + StartBlock( "public static class CallbackIdentifiers" ); + foreach ( var o in def.CallbackIds ) { - if ( SkipTypes.Contains( o.Name ) ) - continue; - - if ( SkipTypesStartingWith.Any( x => o.Name.StartsWith( x ) ) ) - continue; - - StartBlock( $"public struct {o.Name}" ); - { - WriteLine( $"public {ToManagedType( o.Type )} Value;" ); - WriteLine(); - StartBlock( $"public static implicit operator {o.Name}( {ToManagedType( o.Type )} value )" ); - { - WriteLine( $"return new {o.Name}(){{ Value = value }};" ); - } - EndBlock(); - WriteLine(); - StartBlock( $"public static implicit operator {ToManagedType( o.Type )}( {o.Name} value )" ); - { - WriteLine( $"return value.Value;" ); - } - EndBlock(); - } - EndBlock(); - WriteLine(); + WriteLine( $"public const int {o.Key} = {o.Value};" ); } + EndBlock(); + + StartBlock( "public static class Defines" ); + foreach ( var o in def.Defines ) + { + WriteLine( $"public const string {o.Key} = \"{o.Value}\";" ); + } + EndBlock(); } } -} +} \ No newline at end of file diff --git a/Generator/CodeWriter/Types.cs b/Generator/CodeWriter/Types.cs index a998e66..8bce905 100644 --- a/Generator/CodeWriter/Types.cs +++ b/Generator/CodeWriter/Types.cs @@ -1,4 +1,5 @@ -using System; + +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,14 +9,59 @@ namespace Generator { public partial class CodeWriter { - private void Constants() + // + // Don't give a fuck about these types + // + public readonly static string[] SkipTypes = new string[] { - StartBlock( "public static class CallbackIdentifiers" ); - foreach ( var o in def.CallbackIds ) + "ValvePackingSentinel_t", + "SteamAPIWarningMessageHook_t", + "Salt_t", + "SteamAPI_CheckCallbackRegistered_t", + "compile_time_assert_type" + }; + + // + // Native types and function defs + // + public readonly static string[] SkipTypesStartingWith = new string[] + { + "uint", + "int", + "ulint", + "lint", + "PFN" + }; + + private void Types() + { + foreach ( var o in def.typedefs.Where( x => !x.Name.Contains( "::" ) ) ) { - WriteLine( $"public const int {o.Key} = {o.Value};" ); + if ( SkipTypes.Contains( o.Name ) ) + continue; + + if ( SkipTypesStartingWith.Any( x => o.Name.StartsWith( x ) ) ) + continue; + + StartBlock( $"public struct {o.Name}" ); + { + WriteLine( $"public {ToManagedType( o.Type )} Value;" ); + WriteLine(); + StartBlock( $"public static implicit operator {o.Name}( {ToManagedType( o.Type )} value )" ); + { + WriteLine( $"return new {o.Name}(){{ Value = value }};" ); + } + EndBlock(); + WriteLine(); + StartBlock( $"public static implicit operator {ToManagedType( o.Type )}( {o.Name} value )" ); + { + WriteLine( $"return value.Value;" ); + } + EndBlock(); + } + EndBlock(); + WriteLine(); } - EndBlock(); } } } diff --git a/Generator/SteamApiDefinition.cs b/Generator/SteamApiDefinition.cs index 8b73890..8aeef0e 100644 --- a/Generator/SteamApiDefinition.cs +++ b/Generator/SteamApiDefinition.cs @@ -83,5 +83,6 @@ public class ParamType public Dictionary CallbackIds { get; internal set; } + public Dictionary Defines { get; internal set; } } }