From 778faa10492afe1c983e440e4e20db922d9e4aef Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Sat, 29 Oct 2016 20:50:40 +0100 Subject: [PATCH] Use generated structs where possible --- Facepunch.Steamworks/Callbacks/Index.cs | 8 -- Facepunch.Steamworks/Callbacks/Networking.cs | 27 ------ Facepunch.Steamworks/Callbacks/User.cs | 34 -------- Facepunch.Steamworks/Callbacks/Workshop.cs | 85 ++----------------- .../Facepunch.Steamworks.csproj | 2 - Facepunch.Steamworks/Interfaces/Networking.cs | 19 ++--- .../Interfaces/Workshop.Editor.cs | 14 +-- .../Interfaces/Workshop.Item.cs | 1 - .../Interfaces/Workshop.Query.cs | 2 +- Facepunch.Steamworks/Interfaces/Workshop.cs | 8 +- Facepunch.Steamworks/Server/Auth.cs | 30 +++---- .../SteamNative/SteamNative.Structs.cs | 21 +++-- Generator/CodeParser/CodeParser.cs | 2 +- Generator/CodeWriter/Utility.cs | 1 + 14 files changed, 55 insertions(+), 199 deletions(-) delete mode 100644 Facepunch.Steamworks/Callbacks/Networking.cs delete mode 100644 Facepunch.Steamworks/Callbacks/User.cs diff --git a/Facepunch.Steamworks/Callbacks/Index.cs b/Facepunch.Steamworks/Callbacks/Index.cs index 5904b7e..fce857f 100644 --- a/Facepunch.Steamworks/Callbacks/Index.cs +++ b/Facepunch.Steamworks/Callbacks/Index.cs @@ -5,14 +5,6 @@ using System.Text; namespace Facepunch.Steamworks.Callbacks { - internal static class Index - { - internal const int User = 100; - internal const int Networking = 1200; - internal const int RemoteStorage = 1300; - internal const int UGC = 3400; - } - public enum Result : int { OK = 1, // success diff --git a/Facepunch.Steamworks/Callbacks/Networking.cs b/Facepunch.Steamworks/Callbacks/Networking.cs deleted file mode 100644 index dd77ffd..0000000 --- a/Facepunch.Steamworks/Callbacks/Networking.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; - -namespace Facepunch.Steamworks.Callbacks.Networking -{ - [StructLayout( LayoutKind.Sequential, Pack = 1 )] - internal class P2PSessionRequest - { - public ulong SteamID; - - public const int CallbackId = Index.Networking + 2; - }; - - [StructLayout( LayoutKind.Sequential, Pack = 1 )] - internal class P2PSessionConnectFail - { - public ulong SteamID; - public Steamworks.Networking.SessionError Error; - - public const int CallbackId = Index.Networking + 3; - }; - - -} diff --git a/Facepunch.Steamworks/Callbacks/User.cs b/Facepunch.Steamworks/Callbacks/User.cs deleted file mode 100644 index 5958531..0000000 --- a/Facepunch.Steamworks/Callbacks/User.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; - -namespace Facepunch.Steamworks.Callbacks.User -{ - [StructLayout( LayoutKind.Sequential, Pack = 4 )] - internal struct ValidateAuthTicketResponse - { - public ulong SteamID; - public int AuthResponse; - public ulong OwnerSteamID; - - public const int CallbackId = Index.User + 43; - - public enum Response : int - { - Okay = 0, // Steam has verified the user is online, the ticket is valid and ticket has not been reused. - UserNotConnectedToSteam = 1, // The user in question is not connected to steam - NoLicenseOrExpired = 2, // The license has expired. - VACBanned = 3, // The user is VAC banned for this game. - LoggedInElseWhere = 4, // The user account has logged in elsewhere and the session containing the game instance has been disconnected. - VACCheckTimedOut = 5, // VAC has been unable to perform anti-cheat checks on this user - AuthTicketCanceled = 6, // The ticket has been canceled by the issuer - AuthTicketInvalidAlreadyUsed = 7, // This ticket has already been used, it is not valid. - AuthTicketInvalid = 8, // This ticket is not from a user instance currently connected to steam. - PublisherIssuedBan = 9, // The user is banned for this game. The ban came via the web api and not VAC - }; - }; - - -} diff --git a/Facepunch.Steamworks/Callbacks/Workshop.cs b/Facepunch.Steamworks/Callbacks/Workshop.cs index 1c4b02d..3357ffe 100644 --- a/Facepunch.Steamworks/Callbacks/Workshop.cs +++ b/Facepunch.Steamworks/Callbacks/Workshop.cs @@ -3,14 +3,13 @@ using Facepunch.Steamworks.Interop; namespace Facepunch.Steamworks.Callbacks.Workshop { - [StructLayout( LayoutKind.Sequential, Pack = 8 )] internal struct ItemInstalled { public uint AppId; public ulong FileId; - public const int CallbackId = Index.UGC + 5; + public const int CallbackId = SteamNative.CallbackIdentifiers.ClientUGC + 5; [StructLayout( LayoutKind.Sequential, Pack = 4 )] internal struct Small @@ -20,90 +19,20 @@ namespace Facepunch.Steamworks.Callbacks.Workshop }; }; - [StructLayout( LayoutKind.Sequential, Pack = 8 )] - internal struct DownloadResult + internal class QueryCompleted : CallResult { - public uint AppId; - public ulong FileId; - public Result Result; - - public const int CallbackId = Index.UGC + 6; - - [StructLayout( LayoutKind.Sequential, Pack = 4 )] - internal struct Small - { - public uint AppId; - public ulong FileId; - public Result Result; - }; - }; - - - internal class QueryCompleted : CallResult - { - public override int CallbackId { get { return Index.UGC + 1; } } - - [StructLayout( LayoutKind.Sequential, Pack = 8 )] - internal struct Data - { - internal ulong Handle; - internal int Result; - internal uint NumResultsReturned; - internal uint TotalMatchingResults; - internal bool CachedData; - - [StructLayout( LayoutKind.Sequential, Pack = 4 )] - internal struct Small - { - internal ulong Handle; - internal int Result; - internal uint NumResultsReturned; - internal uint TotalMatchingResults; - internal bool CachedData; - }; - }; + public override int CallbackId { get { return SteamNative.SteamUGCQueryCompleted_t.CallbackId; } } } - internal class CreateItem : CallResult + internal class CreateItem : CallResult { - public override int CallbackId { get { return Index.UGC + 3; } } - - [StructLayout( LayoutKind.Sequential, Pack = 8 )] - internal struct Data - { - internal Result Result; - internal ulong FileId; - internal bool NeedsLegalAgreement; - - [StructLayout( LayoutKind.Sequential, Pack = 4 )] - internal struct Small - { - internal Result Result; - internal ulong FileId; - - internal bool NeedsLegalAgreement; - }; - }; + public override int CallbackId { get { return SteamNative.CreateItemResult_t.CallbackId; } } } - internal class SubmitItemUpdate : CallResult + internal class SubmitItemUpdate : CallResult { - public override int CallbackId { get { return Index.UGC + 4; } } + public override int CallbackId { get { return SteamNative.SubmitItemUpdateResult_t.CallbackId; } } public SteamNative.UGCUpdateHandle_t UpdateHandle; - - [StructLayout( LayoutKind.Sequential, Pack = 8 )] - internal struct Data - { - internal Result Result; - internal bool NeedsLegalAgreement; - - [StructLayout( LayoutKind.Sequential, Pack = 4 )] - internal struct Small - { - internal Result Result; - internal bool NeedsLegalAgreement; - }; - }; } } diff --git a/Facepunch.Steamworks/Facepunch.Steamworks.csproj b/Facepunch.Steamworks/Facepunch.Steamworks.csproj index 412bb0e..c561a03 100644 --- a/Facepunch.Steamworks/Facepunch.Steamworks.csproj +++ b/Facepunch.Steamworks/Facepunch.Steamworks.csproj @@ -114,7 +114,6 @@ - @@ -134,7 +133,6 @@ - diff --git a/Facepunch.Steamworks/Interfaces/Networking.cs b/Facepunch.Steamworks/Interfaces/Networking.cs index 3a58293..11308b7 100644 --- a/Facepunch.Steamworks/Interfaces/Networking.cs +++ b/Facepunch.Steamworks/Interfaces/Networking.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; -using Facepunch.Steamworks.Callbacks.Networking; namespace Facepunch.Steamworks { @@ -19,8 +18,8 @@ namespace Facepunch.Steamworks { this.networking = networking; - sw.AddCallback( onP2PConnectionRequest, P2PSessionRequest.CallbackId ); - sw.AddCallback( onP2PConnectionFailed, P2PSessionConnectFail.CallbackId ); + sw.AddCallback( onP2PConnectionRequest, SteamNative.P2PSessionRequest_t.CallbackId ); + sw.AddCallback( onP2PConnectionFailed, SteamNative.P2PSessionConnectFail_t.CallbackId ); } public void Dispose() @@ -47,19 +46,19 @@ namespace Facepunch.Steamworks } } - private void onP2PConnectionRequest( P2PSessionRequest o, bool b ) + private void onP2PConnectionRequest( SteamNative.P2PSessionRequest_t o, bool b ) { if ( OnIncomingConnection != null ) { - var accept = OnIncomingConnection( o.SteamID ); + var accept = OnIncomingConnection( o.SteamIDRemote ); if ( accept ) { - networking.AcceptP2PSessionWithUser( o.SteamID ); + networking.AcceptP2PSessionWithUser( o.SteamIDRemote ); } else { - networking.CloseP2PSessionWithUser( o.SteamID ); + networking.CloseP2PSessionWithUser( o.SteamIDRemote ); } return; @@ -68,7 +67,7 @@ namespace Facepunch.Steamworks // // Default is to reject the session // - networking.CloseP2PSessionWithUser( o.SteamID ); + networking.CloseP2PSessionWithUser( o.SteamIDRemote ); } public enum SessionError : byte @@ -83,11 +82,11 @@ namespace Facepunch.Steamworks Max = 5 }; - private void onP2PConnectionFailed( P2PSessionConnectFail o, bool b ) + private void onP2PConnectionFailed( SteamNative.P2PSessionConnectFail_t o, bool b ) { if ( OnConnectionFailed != null ) { - OnConnectionFailed( o.SteamID, o.Error ); + OnConnectionFailed( o.SteamIDRemote, (SessionError) o.P2PSessionError ); } } diff --git a/Facepunch.Steamworks/Interfaces/Workshop.Editor.cs b/Facepunch.Steamworks/Interfaces/Workshop.Editor.cs index 3ead924..df13a83 100644 --- a/Facepunch.Steamworks/Interfaces/Workshop.Editor.cs +++ b/Facepunch.Steamworks/Interfaces/Workshop.Editor.cs @@ -114,14 +114,14 @@ namespace Facepunch.Steamworks workshop.steamworks.AddCallResult( CreateItem ); } - private void OnItemCreated( CreateItem.Data obj ) + private void OnItemCreated( SteamNative.CreateItemResult_t obj ) { - NeedToAgreeToWorkshopLegal = obj.NeedsLegalAgreement; + NeedToAgreeToWorkshopLegal = obj.UserNeedsToAcceptWorkshopLegalAgreement; CreateItem = null; - if ( obj.Result == Callbacks.Result.OK ) + if ( obj.Result == SteamNative.Result.OK ) { - Id = obj.FileId; + Id = obj.PublishedFileId; PublishChanges(); return; } @@ -171,13 +171,13 @@ namespace Facepunch.Steamworks workshop.steamworks.AddCallResult( SubmitItemUpdate ); } - private void OnChangesSubmitted( SubmitItemUpdate.Data obj ) + private void OnChangesSubmitted( SteamNative.SubmitItemUpdateResult_t obj ) { SubmitItemUpdate = null; - NeedToAgreeToWorkshopLegal = obj.NeedsLegalAgreement; + NeedToAgreeToWorkshopLegal = obj.UserNeedsToAcceptWorkshopLegalAgreement; Publishing = false; - if ( obj.Result == Callbacks.Result.OK ) + if ( obj.Result == SteamNative.Result.OK ) { return; } diff --git a/Facepunch.Steamworks/Interfaces/Workshop.Item.cs b/Facepunch.Steamworks/Interfaces/Workshop.Item.cs index bdab8f0..936d6e2 100644 --- a/Facepunch.Steamworks/Interfaces/Workshop.Item.cs +++ b/Facepunch.Steamworks/Interfaces/Workshop.Item.cs @@ -4,7 +4,6 @@ using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; -using Facepunch.Steamworks.Callbacks.Networking; using Facepunch.Steamworks.Callbacks.Workshop; namespace Facepunch.Steamworks diff --git a/Facepunch.Steamworks/Interfaces/Workshop.Query.cs b/Facepunch.Steamworks/Interfaces/Workshop.Query.cs index 4c307eb..9bed7c8 100644 --- a/Facepunch.Steamworks/Interfaces/Workshop.Query.cs +++ b/Facepunch.Steamworks/Interfaces/Workshop.Query.cs @@ -114,7 +114,7 @@ namespace Facepunch.Steamworks workshop.steamworks.AddCallResult( Callback ); } - void OnResult( QueryCompleted.Data data ) + void OnResult( SteamNative.SteamUGCQueryCompleted_t data ) { var gotFiles = 0; for ( int i = 0; i < data.NumResultsReturned; i++ ) diff --git a/Facepunch.Steamworks/Interfaces/Workshop.cs b/Facepunch.Steamworks/Interfaces/Workshop.cs index 520238e..381a7c9 100644 --- a/Facepunch.Steamworks/Interfaces/Workshop.cs +++ b/Facepunch.Steamworks/Interfaces/Workshop.cs @@ -22,8 +22,8 @@ namespace Facepunch.Steamworks this.steamworks = steamworks; this.remoteStorage = remoteStorage; - steamworks.AddCallback( onDownloadResult, DownloadResult.CallbackId ); - steamworks.AddCallback( onItemInstalled, ItemInstalled.CallbackId ); + steamworks.AddCallback( onDownloadResult, SteamNative.DownloadItemResult_t.CallbackId ); + steamworks.AddCallback( onItemInstalled, ItemInstalled.CallbackId ); } public void Dispose() @@ -43,10 +43,10 @@ namespace Facepunch.Steamworks OnItemInstalled( obj.FileId ); } - private void onDownloadResult( DownloadResult obj, bool failed ) + private void onDownloadResult( SteamNative.DownloadItemResult_t obj, bool failed ) { if ( OnFileDownloaded != null ) - OnFileDownloaded( obj.FileId, obj.Result ); + OnFileDownloaded( obj.PublishedFileId, (Callbacks.Result) obj.Result ); } public Query CreateQuery() diff --git a/Facepunch.Steamworks/Server/Auth.cs b/Facepunch.Steamworks/Server/Auth.cs index 3448950..244e4b7 100644 --- a/Facepunch.Steamworks/Server/Auth.cs +++ b/Facepunch.Steamworks/Server/Auth.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using Facepunch.Steamworks.Callbacks.User; namespace Facepunch.Steamworks { @@ -36,32 +35,29 @@ namespace Facepunch.Steamworks /// public enum Status : int { - /// - /// Steam has verified the user is online, the ticket is valid and ticket has not been reused. - /// - OK = 0, - UserNotConnectedToSteam = 1, // The user in question is not connected to steam - NoLicenseOrExpired = 2, // The license has expired. - VACBanned = 3, // The user is VAC banned for this game. - LoggedInElseWhere = 4, // The user account has logged in elsewhere and the session containing the game instance has been disconnected. - VACCheckTimedOut = 5, // VAC has been unable to perform anti-cheat checks on this user - AuthTicketCanceled = 6, // The ticket has been canceled by the issuer - AuthTicketInvalidAlreadyUsed = 7, // This ticket has already been used, it is not valid. - AuthTicketInvalid = 8, // This ticket is not from a user instance currently connected to steam. - PublisherIssuedBan = 9, // The user is banned for this game. The ban came via the web api and not VAC + OK = 0, + UserNotConnectedToSteam = 1, + NoLicenseOrExpired = 2, + VACBanned = 3, + LoggedInElseWhere = 4, + VACCheckTimedOut = 5, + AuthTicketCanceled = 6, + AuthTicketInvalidAlreadyUsed = 7, + AuthTicketInvalid = 8, + PublisherIssuedBan = 9, } internal ServerAuth( Server s ) { server = s; - server.AddCallback( OnAuthTicketValidate, ValidateAuthTicketResponse.CallbackId ); + server.AddCallback( OnAuthTicketValidate, SteamNative.ValidateAuthTicketResponse_t.CallbackId ); } - void OnAuthTicketValidate( ValidateAuthTicketResponse data, bool b ) + void OnAuthTicketValidate( SteamNative.ValidateAuthTicketResponse_t data, bool b ) { if ( OnAuthChange != null ) - OnAuthChange( data.SteamID, data.OwnerSteamID, (Status) data.AuthResponse ); + OnAuthChange( data.SteamID, data.OwnerSteamID, (Status) data.AuthSessionResponse ); } /// diff --git a/Facepunch.Steamworks/SteamNative/SteamNative.Structs.cs b/Facepunch.Steamworks/SteamNative/SteamNative.Structs.cs index 139f169..591d866 100644 --- a/Facepunch.Steamworks/SteamNative/SteamNative.Structs.cs +++ b/Facepunch.Steamworks/SteamNative/SteamNative.Structs.cs @@ -4651,6 +4651,7 @@ namespace SteamNative [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct P2PSessionRequest_t { + public const int CallbackId = CallbackIdentifiers.SteamNetworking + 2; public ulong SteamIDRemote; // m_steamIDRemote class CSteamID // @@ -4690,6 +4691,7 @@ namespace SteamNative [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct P2PSessionConnectFail_t { + public const int CallbackId = CallbackIdentifiers.SteamNetworking + 3; public ulong SteamIDRemote; // m_steamIDRemote class CSteamID public byte P2PSessionError; // m_eP2PSessionError uint8 @@ -4732,6 +4734,7 @@ namespace SteamNative [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct SocketStatusCallback_t { + public const int CallbackId = CallbackIdentifiers.SteamNetworking + 1; public uint Socket; // m_hSocket SNetSocket_t public uint ListenSocket; // m_hListenSocket SNetListenSocket_t public ulong SteamIDRemote; // m_steamIDRemote class CSteamID @@ -5588,7 +5591,7 @@ namespace SteamNative public struct SteamUGCQueryCompleted_t { public const int CallbackId = CallbackIdentifiers.ClientUGC + 1; - public ulong Andle; // m_handle UGCQueryHandle_t + public ulong Handle; // m_handle UGCQueryHandle_t public Result Result; // m_eResult enum EResult public uint NumResultsReturned; // m_unNumResultsReturned uint32 public uint TotalMatchingResults; // m_unTotalMatchingResults uint32 @@ -5606,7 +5609,7 @@ namespace SteamNative [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct PackSmall { - public ulong Andle; // m_handle UGCQueryHandle_t + public ulong Handle; // m_handle UGCQueryHandle_t public Result Result; // m_eResult enum EResult public uint NumResultsReturned; // m_unNumResultsReturned uint32 public uint TotalMatchingResults; // m_unTotalMatchingResults uint32 @@ -5620,7 +5623,7 @@ namespace SteamNative { return new SteamUGCQueryCompleted_t() { - Andle = d.Andle, + Handle = d.Handle, Result = d.Result, NumResultsReturned = d.NumResultsReturned, TotalMatchingResults = d.TotalMatchingResults, @@ -7233,7 +7236,7 @@ namespace SteamNative public struct SteamInventoryResultReady_t { public const int CallbackId = CallbackIdentifiers.ClientInventory + 0; - public int Andle; // m_handle SteamInventoryResult_t + public int Handle; // m_handle SteamInventoryResult_t public Result Esult; // m_result enum EResult // @@ -7247,7 +7250,7 @@ namespace SteamNative [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct PackSmall { - public int Andle; // m_handle SteamInventoryResult_t + public int Handle; // m_handle SteamInventoryResult_t public Result Esult; // m_result enum EResult // @@ -7257,7 +7260,7 @@ namespace SteamNative { return new SteamInventoryResultReady_t() { - Andle = d.Andle, + Handle = d.Handle, Esult = d.Esult, }; } @@ -7276,7 +7279,7 @@ namespace SteamNative public struct SteamInventoryFullUpdate_t { public const int CallbackId = CallbackIdentifiers.ClientInventory + 1; - public int Andle; // m_handle SteamInventoryResult_t + public int Handle; // m_handle SteamInventoryResult_t // // Read this struct from a pointer, usually from Native @@ -7289,7 +7292,7 @@ namespace SteamNative [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct PackSmall { - public int Andle; // m_handle SteamInventoryResult_t + public int Handle; // m_handle SteamInventoryResult_t // // Easily convert from PackSmall to SteamInventoryFullUpdate_t @@ -7298,7 +7301,7 @@ namespace SteamNative { return new SteamInventoryFullUpdate_t() { - Andle = d.Andle, + Handle = d.Handle, }; } diff --git a/Generator/CodeParser/CodeParser.cs b/Generator/CodeParser/CodeParser.cs index 0e1f544..c82a287 100644 --- a/Generator/CodeParser/CodeParser.cs +++ b/Generator/CodeParser/CodeParser.cs @@ -41,7 +41,7 @@ namespace Generator { Console.WriteLine( t.Name ); - var r = new Regex( @"struct "+t.Name+@"\n{\n(?:.)+enum { k_iCallback = (.+) \+ ([0-9]+)", RegexOptions.Multiline | RegexOptions.IgnoreCase ); + var r = new Regex( @"struct "+t.Name+@"\n{ ?\n(?:.)+enum { k_iCallback = (.+) \+ ([0-9]+)", RegexOptions.Multiline | RegexOptions.IgnoreCase ); var m = r.Match( Content ); if ( m.Success ) { diff --git a/Generator/CodeWriter/Utility.cs b/Generator/CodeWriter/Utility.cs index 5e8215f..4843e86 100644 --- a/Generator/CodeWriter/Utility.cs +++ b/Generator/CodeWriter/Utility.cs @@ -35,6 +35,7 @@ namespace Generator if ( m == "m_pubParam" ) return "ParamPtr"; if ( m == "m_cubParam" ) return "ParamCount"; if ( m == "m_itemId" ) return "ItemId"; + if ( m == "m_handle" ) return "Handle"; var cleanName = m.Replace( "m_un", "" ) .Replace( "m_us", "" )