Skip to content

Commit

Permalink
Use RequestUserStats.
Browse files Browse the repository at this point in the history
- Replace SteamUserStats007 with SteamUserStats013.
- Replace deprecated usage of RequestCurrentStats
  with RequestUserStats.

Fixes #378 #389 #397 #398 #401 #411 #413
gibbed committed Sep 15, 2024
1 parent c2711eb commit b3a66df
Showing 5 changed files with 39 additions and 27 deletions.
4 changes: 2 additions & 2 deletions SAM.API/Client.cs
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ public class Client : IDisposable
{
public Wrappers.SteamClient018 SteamClient;
public Wrappers.SteamUser012 SteamUser;
public Wrappers.SteamUserStats007 SteamUserStats;
public Wrappers.SteamUserStats013 SteamUserStats;
public Wrappers.SteamUtils005 SteamUtils;
public Wrappers.SteamApps001 SteamApps001;
public Wrappers.SteamApps008 SteamApps008;
@@ -84,7 +84,7 @@ public void Initialize(long appId)
}

this.SteamUser = this.SteamClient.GetSteamUser012(this._User, this._Pipe);
this.SteamUserStats = this.SteamClient.GetSteamUserStats006(this._User, this._Pipe);
this.SteamUserStats = this.SteamClient.GetSteamUserStats013(this._User, this._Pipe);
this.SteamApps001 = this.SteamClient.GetSteamApps001(this._User, this._Pipe);
this.SteamApps008 = this.SteamClient.GetSteamApps008(this._User, this._Pipe);
}
Original file line number Diff line number Diff line change
@@ -26,9 +26,8 @@
namespace SAM.API.Interfaces
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class ISteamUserStats007
public class ISteamUserStats013
{
public IntPtr RequestCurrentStats;
public IntPtr GetStatFloat;
public IntPtr GetStatInteger;
public IntPtr SetStatFloat;
@@ -42,6 +41,8 @@ public class ISteamUserStats007
public IntPtr GetAchievementIcon;
public IntPtr GetAchievementDisplayAttribute;
public IntPtr IndicateAchievementProgress;
public IntPtr GetNumAchievements;
public IntPtr GetAchievementName;
public IntPtr RequestUserStats;
public IntPtr GetUserStatFloat;
public IntPtr GetUserStatInt;
@@ -55,8 +56,21 @@ public class ISteamUserStats007
public IntPtr GetLeaderboardSortMethod;
public IntPtr GetLeaderboardDisplayType;
public IntPtr DownloadLeaderboardEntries;
public IntPtr DownloadLeaderboardEntriesForUsers;
public IntPtr GetDownloadedLeaderboardEntry;
public IntPtr UploadLeaderboardScore;
public IntPtr AttachLeaderboardUGC;
public IntPtr GetNumberOfCurrentPlayers;
public IntPtr RequestGlobalAchievementPercentages;
public IntPtr GetMostAchievedAchievementInfo;
public IntPtr GetNextMostAchievedAchievementInfo;
public IntPtr GetAchievementAchievedPercent;
public IntPtr RequestGlobalStats;
public IntPtr GetGlobalStatFloat;
public IntPtr GetGlobalStatInteger;
public IntPtr GetGlobalStatHistoryFloat;
public IntPtr GetGlobalStatHistoryInteger;
public IntPtr GetAchievementProgressLimitsFloat;
public IntPtr GetAchievementProgressLimitsInteger;
}
}
6 changes: 3 additions & 3 deletions SAM.API/Wrappers/SteamClient018.cs
Original file line number Diff line number Diff line change
@@ -144,10 +144,10 @@ private TClass GetISteamUserStats<TClass>(int user, int pipe, string version)
}
#endregion

#region GetSteamUserStats007
public SteamUserStats007 GetSteamUserStats006(int user, int pipe)
#region GetSteamUserStats013
public SteamUserStats013 GetSteamUserStats013(int user, int pipe)
{
return this.GetISteamUserStats<SteamUserStats007>(user, pipe, "STEAMUSERSTATS_INTERFACE_VERSION007");
return this.GetISteamUserStats<SteamUserStats013>(user, pipe, "STEAMUSERSTATS_INTERFACE_VERSION013");
}
#endregion

Original file line number Diff line number Diff line change
@@ -26,19 +26,8 @@

namespace SAM.API.Wrappers
{
public class SteamUserStats007 : NativeWrapper<ISteamUserStats007>
public class SteamUserStats013 : NativeWrapper<ISteamUserStats013>
{
#region RequestCurrentStats
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
[return: MarshalAs(UnmanagedType.I1)]
private delegate bool NativeRequestCurrentStats(IntPtr self);

public bool RequestCurrentStats()
{
return this.Call<bool, NativeRequestCurrentStats>(this.Functions.RequestCurrentStats, this.ObjectAddress);
}
#endregion

#region GetStatValue (int)
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
[return: MarshalAs(UnmanagedType.I1)]
@@ -198,6 +187,17 @@ public string GetAchievementDisplayAttribute(string name, string key)
}
#endregion

#region RequestUserStats
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
[return: MarshalAs(UnmanagedType.I1)]
private delegate bool NativeRequestUserStats(IntPtr self, ulong steamIdUser);

public bool RequestUserStats(ulong steamIdUser)
{
return this.Call<bool, NativeRequestUserStats>(this.Functions.RequestUserStats, this.ObjectAddress, steamIdUser);
}
#endregion

#region ResetAllStats
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
[return: MarshalAs(UnmanagedType.I1)]
14 changes: 6 additions & 8 deletions SAM.Game/Manager.cs
Original file line number Diff line number Diff line change
@@ -206,26 +206,22 @@ private static string GetLocalizedString(KeyValue kv, string language, string de
private bool LoadUserGameStatsSchema()
{
string path;

try
{
string fileName = _($"UserGameStatsSchema_{this._GameId}.bin");
path = API.Steam.GetInstallPath();
path = Path.Combine(path, "appcache");
path = Path.Combine(path, "stats");
path = Path.Combine(path, _($"UserGameStatsSchema_{this._GameId}.bin"));

path = Path.Combine(path, "appcache", "stats", fileName);
if (File.Exists(path) == false)
{
return false;
}
}
catch
catch (Exception e)
{
return false;
}

var kv = KeyValue.LoadAsBinary(path);

if (kv == null)
{
return false;
@@ -405,7 +401,9 @@ private void RefreshStats()
this._AchievementListView.Items.Clear();
this._StatisticsDataGridView.Rows.Clear();

if (this._SteamClient.SteamUserStats.RequestCurrentStats() == false)
var steamId = this._SteamClient.SteamUser.GetSteamId();

if (this._SteamClient.SteamUserStats.RequestUserStats(steamId) == false)
{
MessageBox.Show(this, "Failed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;

0 comments on commit b3a66df

Please sign in to comment.