From 79ed6a299a0fbd037c9b1617fa7a1de632f711b8 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Tue, 16 Apr 2019 21:13:55 +0100 Subject: [PATCH] Parser fixes --- .../Generated/Interfaces/ISteamUserStats.cs | 76 ++++++------------- Generator/CodeParser/CodeParser.Class.cs | 2 + Generator/CodeParser/ParseClasses.cs | 43 ++++++++++- Generator/CodeWriter/Types/BaseType.cs | 1 + 4 files changed, 67 insertions(+), 55 deletions(-) diff --git a/Facepunch.Steamworks/Generated/Interfaces/ISteamUserStats.cs b/Facepunch.Steamworks/Generated/Interfaces/ISteamUserStats.cs index 26bc64b..f3a20e8 100644 --- a/Facepunch.Steamworks/Generated/Interfaces/ISteamUserStats.cs +++ b/Facepunch.Steamworks/Generated/Interfaces/ISteamUserStats.cs @@ -46,22 +46,20 @@ public override void InitInternals() GetLeaderboardSortMethodDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 208) ); GetLeaderboardDisplayTypeDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 216) ); DownloadLeaderboardEntriesDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 224) ); - GetDownloadedLeaderboardEntryDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 232) ); - UploadLeaderboardScoreDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 240) ); - AttachLeaderboardUGCDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 248) ); - GetNumberOfCurrentPlayersDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 256) ); - RequestGlobalAchievementPercentagesDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 264) ); - GetMostAchievedAchievementInfoDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 272) ); - GetNextMostAchievedAchievementInfoDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 280) ); - GetAchievementAchievedPercentDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 288) ); - RequestGlobalStatsDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 296) ); - GetGlobalStatDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 304) ); - GetGlobalStat2DelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 312) ); - GetGlobalStatHistoryDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 320) ); - GetGlobalStatHistory2DelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 328) ); - GetTrophySpaceRequiredBeforeInstallDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 336) ); - SetUserStatsDataDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 344) ); - GetUserStatsDataDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 352) ); + DownloadLeaderboardEntriesForUsersDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 232) ); + GetDownloadedLeaderboardEntryDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 240) ); + UploadLeaderboardScoreDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 248) ); + AttachLeaderboardUGCDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 256) ); + GetNumberOfCurrentPlayersDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 264) ); + RequestGlobalAchievementPercentagesDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 272) ); + GetMostAchievedAchievementInfoDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 280) ); + GetNextMostAchievedAchievementInfoDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 288) ); + GetAchievementAchievedPercentDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 296) ); + RequestGlobalStatsDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 304) ); + GetGlobalStatDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 312) ); + GetGlobalStat2DelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 320) ); + GetGlobalStatHistoryDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 328) ); + GetGlobalStatHistory2DelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 336) ); } #region FunctionMeta @@ -400,6 +398,17 @@ internal LeaderboardDisplayType GetLeaderboardDisplayType( SteamLeaderboard_t hS return await (new Result( DownloadLeaderboardEntriesDelegatePointer( Self, hSteamLeaderboard, eLeaderboardDataRequest, nRangeStart, nRangeEnd ) )).GetResult(); } + #region FunctionMeta + [UnmanagedFunctionPointer( CallingConvention.ThisCall )] + private delegate SteamAPICall_t DownloadLeaderboardEntriesForUsersDelegate( IntPtr self, SteamLeaderboard_t hSteamLeaderboard, [In,Out] SteamId[] prgUsers, int cUsers ); + private DownloadLeaderboardEntriesForUsersDelegate DownloadLeaderboardEntriesForUsersDelegatePointer; + + #endregion + internal async Task DownloadLeaderboardEntriesForUsers( SteamLeaderboard_t hSteamLeaderboard, [In,Out] SteamId[] prgUsers, int cUsers ) + { + return await (new Result( DownloadLeaderboardEntriesForUsersDelegatePointer( Self, hSteamLeaderboard, prgUsers, cUsers ) )).GetResult(); + } + #region FunctionMeta [UnmanagedFunctionPointer( CallingConvention.ThisCall )] [return: MarshalAs( UnmanagedType.I1 )] @@ -547,40 +556,5 @@ internal int GetGlobalStatHistory2( string pchStatName, ref double pData, uint c return GetGlobalStatHistory2DelegatePointer( Self, pchStatName, ref pData, cubData ); } - #region FunctionMeta - [UnmanagedFunctionPointer( CallingConvention.ThisCall )] - private delegate ulong GetTrophySpaceRequiredBeforeInstallDelegate( IntPtr self ); - private GetTrophySpaceRequiredBeforeInstallDelegate GetTrophySpaceRequiredBeforeInstallDelegatePointer; - - #endregion - internal ulong GetTrophySpaceRequiredBeforeInstall() - { - return GetTrophySpaceRequiredBeforeInstallDelegatePointer( Self ); - } - - #region FunctionMeta - [UnmanagedFunctionPointer( CallingConvention.ThisCall )] - [return: MarshalAs( UnmanagedType.I1 )] - private delegate bool SetUserStatsDataDelegate( IntPtr self, IntPtr pvData, uint cubData ); - private SetUserStatsDataDelegate SetUserStatsDataDelegatePointer; - - #endregion - internal bool SetUserStatsData( IntPtr pvData, uint cubData ) - { - return SetUserStatsDataDelegatePointer( Self, pvData, cubData ); - } - - #region FunctionMeta - [UnmanagedFunctionPointer( CallingConvention.ThisCall )] - [return: MarshalAs( UnmanagedType.I1 )] - private delegate bool GetUserStatsDataDelegate( IntPtr self, IntPtr pvData, uint cubData, ref uint pcubWritten ); - private GetUserStatsDataDelegate GetUserStatsDataDelegatePointer; - - #endregion - internal bool GetUserStatsData( IntPtr pvData, uint cubData, ref uint pcubWritten ) - { - return GetUserStatsDataDelegatePointer( Self, pvData, cubData, ref pcubWritten ); - } - } } diff --git a/Generator/CodeParser/CodeParser.Class.cs b/Generator/CodeParser/CodeParser.Class.cs index d9d59a0..92e830b 100644 --- a/Generator/CodeParser/CodeParser.Class.cs +++ b/Generator/CodeParser/CodeParser.Class.cs @@ -30,6 +30,8 @@ internal Function AddFunction( string funcName, string returnType, string args ) ReturnType = returnType }; + args = Regex.Replace( args, "", "" ); + foreach ( var arg in args.Split( new[] { ',' }, StringSplitOptions.RemoveEmptyEntries ) ) { var m = Regex.Match( arg.Trim(), @"(.+?[ |\*])?([a-zA-Z0-9_]+?)( = (.+?))?$" ); diff --git a/Generator/CodeParser/ParseClasses.cs b/Generator/CodeParser/ParseClasses.cs index df1dd46..ac14be1 100644 --- a/Generator/CodeParser/ParseClasses.cs +++ b/Generator/CodeParser/ParseClasses.cs @@ -48,25 +48,52 @@ public void ProcessClass( string fulldef, string classname, string inner ) var lastCallResult = ""; - foreach ( var line in lines ) + var partialLine = ""; + + var needsEndIf = false; + + foreach ( var linestr in lines ) { + var line = linestr; + if ( line.Trim().Length < 4 ) continue; if ( line.Trim().StartsWith( "public:" ) ) continue; if ( line.Trim().StartsWith( "//" ) ) continue; + if ( line.Trim().StartsWith( "#ifdef _PS3" ) ) + { + needsEndIf = true; + continue; + } + + if ( needsEndIf ) + { + needsEndIf = !line.Trim().StartsWith( "#endif" ); + continue; + } + var callresult = Regex.Match( line, @"STEAM_CALL_RESULT\((.+?)\)" ); if ( callresult.Success ) { + partialLine = ""; lastCallResult = callresult.Groups[1].Value.Trim(); continue; } + if ( !string.IsNullOrEmpty( partialLine ) ) + { + partialLine += " " + line.Trim(); + + if ( !partialLine.Trim().EndsWith( ";" ) ) + continue; + + line = partialLine; + partialLine = ""; + } + var f = func.Match( line ); if ( f.Success ) { - - - var returnType = f.Groups[1].Value.Trim(); var funcName = f.Groups[2].Value.Trim(); var args = f.Groups[3].Value.Trim(); @@ -82,9 +109,15 @@ public void ProcessClass( string fulldef, string classname, string inner ) fnc.CallResult = lastCallResult; lastCallResult = null; + partialLine = ""; } else { + if ( line.Trim().StartsWith( "virtual " ) ) + { + partialLine = line; + } + Console.WriteLine( $"Unknown Line: {line}" ); } } @@ -101,6 +134,8 @@ public string RemoveAnnotations( string str ) str = Regex.Replace( str, @"STEAM_ARRAY_COUNT\((.+?)\) ", "" ); str = Regex.Replace( str, @"STEAM_OUT_STRUCT\(\) ", "" ); str = Regex.Replace( str, @"STEAM_OUT_STRUCT\((.+?)\) ", "" ); + str = Regex.Replace( str, @"STEAM_OUT_ARRAY_COUNT\((.+?)\)", "" ); + str = Regex.Replace( str, @"STEAM_ARRAY_COUNT_D\((.+?)\)", "" ); diff --git a/Generator/CodeWriter/Types/BaseType.cs b/Generator/CodeWriter/Types/BaseType.cs index 29bd929..568f7ae 100644 --- a/Generator/CodeWriter/Types/BaseType.cs +++ b/Generator/CodeWriter/Types/BaseType.cs @@ -61,6 +61,7 @@ public virtual bool IsVector if ( VarName == "psteamIDClans" ) return true; if ( VarName == "pScoreDetails" ) return true; + if ( VarName == "prgUsers" ) return true; if ( NativeType.EndsWith( "**" ) ) return true; if ( NativeType.EndsWith( "*" ) )