Skip to content

Commit

Permalink
Fix return type for RequestUserStats.
Browse files Browse the repository at this point in the history
  • Loading branch information
gibbed committed Sep 15, 2024
1 parent 0a3cd6c commit 7bd6172
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
29 changes: 29 additions & 0 deletions SAM.API/CallHandle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* Copyright (c) 2024 Rick (rick 'at' gibbed 'dot' us)
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would
* be appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not
* be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/

namespace SAM.API
{
public enum CallHandle : ulong
{
Invalid = 0,
}
}
4 changes: 1 addition & 3 deletions SAM.API/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ public void RunCallbacks(bool server)
this._RunningCallbacks = true;

Types.CallbackMessage message;
int call;
while (Steam.GetCallback(this._Pipe, out message, out call) == true)
while (Steam.GetCallback(this._Pipe, out message, out _) == true)
{
var callbackId = message.Id;
foreach (ICallback callback in this._Callbacks.Where(
Expand All @@ -152,7 +151,6 @@ public void RunCallbacks(bool server)
{
callback.Run(message.ParamPointer);
}

Steam.FreeLastCallback(this._Pipe);
}

Expand Down
7 changes: 3 additions & 4 deletions SAM.API/Wrappers/SteamUserStats013.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,11 @@ public string GetAchievementDisplayAttribute(string name, string key)

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

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

Expand Down
5 changes: 4 additions & 1 deletion SAM.Game/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,10 @@ private void RefreshStats()

var steamId = this._SteamClient.SteamUser.GetSteamId();

if (this._SteamClient.SteamUserStats.RequestUserStats(steamId) == false)
// This still triggers the UserStatsReceived callback, in addition to the callresult.
// No need to implement callresults for the time being.
var callHandle = this._SteamClient.SteamUserStats.RequestUserStats(steamId);
if (callHandle == API.CallHandle.Invalid)
{
MessageBox.Show(this, "Failed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
Expand Down

0 comments on commit 7bd6172

Please sign in to comment.