From eb16bebae9ffa5fccc00810feb7c1c95478ecd53 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Wed, 17 Apr 2019 13:33:38 +0100 Subject: [PATCH] Nice name deduplucate --- Facepunch.Steamworks.Test/UserStatsTest.cs | 3 +- .../Generated/Interfaces/ISteamUserStats.cs | 50 +++++++++---------- Facepunch.Steamworks/Structs/Stat.cs | 10 ++-- Generator/CodeParser/CodeParser.Class.cs | 24 ++++----- 4 files changed, 42 insertions(+), 45 deletions(-) diff --git a/Facepunch.Steamworks.Test/UserStatsTest.cs b/Facepunch.Steamworks.Test/UserStatsTest.cs index 8021ac8..5b8766b 100644 --- a/Facepunch.Steamworks.Test/UserStatsTest.cs +++ b/Facepunch.Steamworks.Test/UserStatsTest.cs @@ -182,8 +182,9 @@ public async Task GetStatGlobalHistoryInt() var startups = new Stat( "GMA_X_STARTUPS_STAT" ); var history = await startups.GetGlobalIntDays( 60 ); + Assert.AreNotEqual( 0, history.Length ); - for( int i=0; i< history.Length; i++ ) + for ( int i=0; i< history.Length; i++ ) { Console.WriteLine( $"{i} : {history[i]}" ); } diff --git a/Facepunch.Steamworks/Generated/Interfaces/ISteamUserStats.cs b/Facepunch.Steamworks/Generated/Interfaces/ISteamUserStats.cs index 4654900..931b7bf 100644 --- a/Facepunch.Steamworks/Generated/Interfaces/ISteamUserStats.cs +++ b/Facepunch.Steamworks/Generated/Interfaces/ISteamUserStats.cs @@ -18,9 +18,9 @@ public ISteamUserStats( bool server = false ) : base( server ) public override void InitInternals() { RequestCurrentStatsDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 0) ); - GetStatDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 8) ); + GetStat1DelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 8) ); GetStat2DelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 16) ); - SetStatDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 24) ); + SetStat1DelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 24) ); SetStat2DelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 32) ); UpdateAvgRateStatDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 40) ); GetAchievementDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 48) ); @@ -34,7 +34,7 @@ public override void InitInternals() GetNumAchievementsDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 112) ); GetAchievementNameDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 120) ); RequestUserStatsDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 128) ); - GetUserStatDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 136) ); + GetUserStat1DelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 136) ); GetUserStat2DelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 144) ); GetUserAchievementDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 152) ); GetUserAchievementAndUnlockTimeDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 160) ); @@ -56,9 +56,9 @@ public override void InitInternals() 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) ); + GetGlobalStat1DelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 312) ); GetGlobalStat2DelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 320) ); - GetGlobalStatHistoryDelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 328) ); + GetGlobalStatHistory1DelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 328) ); GetGlobalStatHistory2DelegatePointer = Marshal.GetDelegateForFunctionPointer( Marshal.ReadIntPtr( VTable, 336) ); } @@ -77,13 +77,13 @@ internal bool RequestCurrentStats() #region FunctionMeta [UnmanagedFunctionPointer( CallingConvention.ThisCall )] [return: MarshalAs( UnmanagedType.I1 )] - private delegate bool GetStatDelegate( IntPtr self, string pchName, ref int pData ); - private GetStatDelegate GetStatDelegatePointer; + private delegate bool GetStat1Delegate( IntPtr self, string pchName, ref int pData ); + private GetStat1Delegate GetStat1DelegatePointer; #endregion - internal bool GetStat( string pchName, ref int pData ) + internal bool GetStat1( string pchName, ref int pData ) { - return GetStatDelegatePointer( Self, pchName, ref pData ); + return GetStat1DelegatePointer( Self, pchName, ref pData ); } #region FunctionMeta @@ -101,13 +101,13 @@ internal bool GetStat2( string pchName, ref float pData ) #region FunctionMeta [UnmanagedFunctionPointer( CallingConvention.ThisCall )] [return: MarshalAs( UnmanagedType.I1 )] - private delegate bool SetStatDelegate( IntPtr self, string pchName, int nData ); - private SetStatDelegate SetStatDelegatePointer; + private delegate bool SetStat1Delegate( IntPtr self, string pchName, int nData ); + private SetStat1Delegate SetStat1DelegatePointer; #endregion - internal bool SetStat( string pchName, int nData ) + internal bool SetStat1( string pchName, int nData ) { - return SetStatDelegatePointer( Self, pchName, nData ); + return SetStat1DelegatePointer( Self, pchName, nData ); } #region FunctionMeta @@ -264,13 +264,13 @@ internal string GetAchievementName( uint iAchievement ) #region FunctionMeta [UnmanagedFunctionPointer( CallingConvention.ThisCall )] [return: MarshalAs( UnmanagedType.I1 )] - private delegate bool GetUserStatDelegate( IntPtr self, SteamId steamIDUser, string pchName, ref int pData ); - private GetUserStatDelegate GetUserStatDelegatePointer; + private delegate bool GetUserStat1Delegate( IntPtr self, SteamId steamIDUser, string pchName, ref int pData ); + private GetUserStat1Delegate GetUserStat1DelegatePointer; #endregion - internal bool GetUserStat( SteamId steamIDUser, string pchName, ref int pData ) + internal bool GetUserStat1( SteamId steamIDUser, string pchName, ref int pData ) { - return GetUserStatDelegatePointer( Self, steamIDUser, pchName, ref pData ); + return GetUserStat1DelegatePointer( Self, steamIDUser, pchName, ref pData ); } #region FunctionMeta @@ -513,13 +513,13 @@ internal bool GetAchievementAchievedPercent( string pchName, ref float pflPercen #region FunctionMeta [UnmanagedFunctionPointer( CallingConvention.ThisCall )] [return: MarshalAs( UnmanagedType.I1 )] - private delegate bool GetGlobalStatDelegate( IntPtr self, string pchStatName, ref long pData ); - private GetGlobalStatDelegate GetGlobalStatDelegatePointer; + private delegate bool GetGlobalStat1Delegate( IntPtr self, string pchStatName, ref long pData ); + private GetGlobalStat1Delegate GetGlobalStat1DelegatePointer; #endregion - internal bool GetGlobalStat( string pchStatName, ref long pData ) + internal bool GetGlobalStat1( string pchStatName, ref long pData ) { - return GetGlobalStatDelegatePointer( Self, pchStatName, ref pData ); + return GetGlobalStat1DelegatePointer( Self, pchStatName, ref pData ); } #region FunctionMeta @@ -536,13 +536,13 @@ internal bool GetGlobalStat2( string pchStatName, ref double pData ) #region FunctionMeta [UnmanagedFunctionPointer( CallingConvention.ThisCall )] - private delegate int GetGlobalStatHistoryDelegate( IntPtr self, string pchStatName, [In,Out] long[] pData, uint cubData ); - private GetGlobalStatHistoryDelegate GetGlobalStatHistoryDelegatePointer; + private delegate int GetGlobalStatHistory1Delegate( IntPtr self, string pchStatName, [In,Out] long[] pData, uint cubData ); + private GetGlobalStatHistory1Delegate GetGlobalStatHistory1DelegatePointer; #endregion - internal int GetGlobalStatHistory( string pchStatName, [In,Out] long[] pData, uint cubData ) + internal int GetGlobalStatHistory1( string pchStatName, [In,Out] long[] pData, uint cubData ) { - return GetGlobalStatHistoryDelegatePointer( Self, pchStatName, pData, cubData ); + return GetGlobalStatHistory1DelegatePointer( Self, pchStatName, pData, cubData ); } #region FunctionMeta diff --git a/Facepunch.Steamworks/Structs/Stat.cs b/Facepunch.Steamworks/Structs/Stat.cs index 2e6d4fe..becb57c 100644 --- a/Facepunch.Steamworks/Structs/Stat.cs +++ b/Facepunch.Steamworks/Structs/Stat.cs @@ -45,7 +45,7 @@ public double GetGlobalFloat() public long GetGlobalInt() { long val = 0; - SteamUserStats.Internal.GetGlobalStat( Name, ref val ); + SteamUserStats.Internal.GetGlobalStat1( Name, ref val ); return val; } @@ -56,7 +56,7 @@ public async Task GetGlobalIntDays( int days ) var r = new long[days]; - var rows = SteamUserStats.Internal.GetGlobalStatHistory( Name, r, (uint) r.Length ); + var rows = SteamUserStats.Internal.GetGlobalStatHistory1( Name, r, (uint) r.Length ); if ( days != rows ) r = r.Take( rows ).ToArray(); @@ -101,11 +101,11 @@ public int GetInt() if ( UserId > 0 ) { - SteamUserStats.Internal.GetUserStat( UserId, Name, ref val ); + SteamUserStats.Internal.GetUserStat1( UserId, Name, ref val ); } else { - SteamUserStats.Internal.GetStat( Name, ref val ); + SteamUserStats.Internal.GetStat1( Name, ref val ); } return val; @@ -114,7 +114,7 @@ public int GetInt() public bool Set( int val ) { LocalUserOnly(); - return SteamUserStats.Internal.SetStat( Name, val ); + return SteamUserStats.Internal.SetStat1( Name, val ); } public bool Set( float val ) diff --git a/Generator/CodeParser/CodeParser.Class.cs b/Generator/CodeParser/CodeParser.Class.cs index 92e830b..b132066 100644 --- a/Generator/CodeParser/CodeParser.Class.cs +++ b/Generator/CodeParser/CodeParser.Class.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Text.RegularExpressions; namespace Generator @@ -14,6 +15,7 @@ public class Class public class Function { public string Name; + public string DuplicateName; public Dictionary Arguments = new Dictionary(); public string ReturnType; @@ -51,24 +53,18 @@ internal Function AddFunction( string funcName, string returnType, string args ) public void PostProcess() { - var LastName = ""; - var DuplicateCount = 0; + var duplicateFunctions = Functions + .GroupBy( x => x.Name ) + .Where( x => x.Count() > 1 ); - for (int i=0; i< Functions.Count; i++ ) + foreach ( var group in duplicateFunctions ) { - var ThisName = Functions[i].Name; - - if ( Functions[i].Name == LastName) + var g = group.ToArray(); + for ( int i=0; i< g.Count(); i++ ) { - DuplicateCount++; - Functions[i].Name += $"{DuplicateCount + 1}"; + g[i].DuplicateName = g[i].Name; + g[i].Name = $"{g[i].Name}{i+1}"; } - else - { - DuplicateCount = 0; - } - - LastName = ThisName; } } }