From d4f0031f1e4b316bd448be2a4fba944a79d74310 Mon Sep 17 00:00:00 2001 From: Nicolas Gnyra Date: Mon, 25 Sep 2023 22:54:44 -0400 Subject: [PATCH] Use `sort_method` when comparing scores in `UploadLeaderboardScore` --- dll/steam_user_stats.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dll/steam_user_stats.h b/dll/steam_user_stats.h index 4ff4163..5eef49c 100644 --- a/dll/steam_user_stats.h +++ b/dll/steam_user_stats.h @@ -18,12 +18,13 @@ #ifndef __INCLUDED_STEAM_USER_STATS_H__ #define __INCLUDED_STEAM_USER_STATS_H__ +#include #include "base.h" #include "../overlay_experimental/steam_overlay.h" struct Steam_Leaderboard_Score { CSteamID steam_id; - int32 score = 0; + int32 score; std::vector score_details; }; @@ -831,6 +832,7 @@ SteamAPICall_t FindOrCreateLeaderboard( const char *pchLeaderboardName, ELeaderb leaderboard.name = std::string(pchLeaderboardName); leaderboard.sort_method = eLeaderboardSortMethod; leaderboard.display_type = eLeaderboardDisplayType; + leaderboard.self_score.score = eLeaderboardSortMethod == k_ELeaderboardSortMethodAscending ? INT_MAX : INT_MIN; std::vector scores = load_leaderboard_scores(pchLeaderboardName); for (auto &s : scores) { @@ -1021,7 +1023,9 @@ SteamAPICall_t UploadLeaderboardScore( SteamLeaderboard_t hSteamLeaderboard, ELe bool changed = false; if (eLeaderboardUploadScoreMethod == k_ELeaderboardUploadScoreMethodKeepBest) { - if (leaderboards[hSteamLeaderboard - 1].self_score.score <= score.score) { + if (leaderboards[hSteamLeaderboard - 1].sort_method == k_ELeaderboardSortMethodAscending + ? leaderboards[hSteamLeaderboard - 1].self_score.score >= score.score + : leaderboards[hSteamLeaderboard - 1].self_score.score <= score.score) { leaderboards[hSteamLeaderboard - 1].self_score = score; changed = true; }