isteamuserstats.cs (26944B)
1 // This file is provided under The MIT License as part of Steamworks.NET. 2 // Copyright (c) 2013-2019 Riley Labrecque 3 // Please see the included LICENSE.txt for additional information. 4 5 // This file is automatically generated. 6 // Changes to this file will be reverted when you update Steamworks.NET 7 8 #if UNITY_ANDROID || UNITY_IOS || UNITY_TIZEN || UNITY_TVOS || UNITY_WEBGL || UNITY_WSA || UNITY_PS4 || UNITY_WII || UNITY_XBOXONE || UNITY_SWITCH 9 #define DISABLESTEAMWORKS 10 #endif 11 12 #if !DISABLESTEAMWORKS 13 14 using System.Runtime.InteropServices; 15 using IntPtr = System.IntPtr; 16 17 namespace Steamworks { 18 public static class SteamUserStats { 19 /// <summary> 20 /// <para> Ask the server to send down this user's data and achievements for this game</para> 21 /// </summary> 22 public static bool RequestCurrentStats() { 23 InteropHelp.TestIfAvailableClient(); 24 return NativeMethods.ISteamUserStats_RequestCurrentStats(CSteamAPIContext.GetSteamUserStats()); 25 } 26 27 /// <summary> 28 /// <para> Data accessors</para> 29 /// </summary> 30 public static bool GetStat(string pchName, out int pData) { 31 InteropHelp.TestIfAvailableClient(); 32 using (var pchName2 = new InteropHelp.UTF8StringHandle(pchName)) { 33 return NativeMethods.ISteamUserStats_GetStat(CSteamAPIContext.GetSteamUserStats(), pchName2, out pData); 34 } 35 } 36 37 public static bool GetStat(string pchName, out float pData) { 38 InteropHelp.TestIfAvailableClient(); 39 using (var pchName2 = new InteropHelp.UTF8StringHandle(pchName)) { 40 return NativeMethods.ISteamUserStats_GetStat0(CSteamAPIContext.GetSteamUserStats(), pchName2, out pData); 41 } 42 } 43 44 /// <summary> 45 /// <para> Set / update data</para> 46 /// </summary> 47 public static bool SetStat(string pchName, int nData) { 48 InteropHelp.TestIfAvailableClient(); 49 using (var pchName2 = new InteropHelp.UTF8StringHandle(pchName)) { 50 return NativeMethods.ISteamUserStats_SetStat(CSteamAPIContext.GetSteamUserStats(), pchName2, nData); 51 } 52 } 53 54 public static bool SetStat(string pchName, float fData) { 55 InteropHelp.TestIfAvailableClient(); 56 using (var pchName2 = new InteropHelp.UTF8StringHandle(pchName)) { 57 return NativeMethods.ISteamUserStats_SetStat0(CSteamAPIContext.GetSteamUserStats(), pchName2, fData); 58 } 59 } 60 61 public static bool UpdateAvgRateStat(string pchName, float flCountThisSession, double dSessionLength) { 62 InteropHelp.TestIfAvailableClient(); 63 using (var pchName2 = new InteropHelp.UTF8StringHandle(pchName)) { 64 return NativeMethods.ISteamUserStats_UpdateAvgRateStat(CSteamAPIContext.GetSteamUserStats(), pchName2, flCountThisSession, dSessionLength); 65 } 66 } 67 68 /// <summary> 69 /// <para> Achievement flag accessors</para> 70 /// </summary> 71 public static bool GetAchievement(string pchName, out bool pbAchieved) { 72 InteropHelp.TestIfAvailableClient(); 73 using (var pchName2 = new InteropHelp.UTF8StringHandle(pchName)) { 74 return NativeMethods.ISteamUserStats_GetAchievement(CSteamAPIContext.GetSteamUserStats(), pchName2, out pbAchieved); 75 } 76 } 77 78 public static bool SetAchievement(string pchName) { 79 InteropHelp.TestIfAvailableClient(); 80 using (var pchName2 = new InteropHelp.UTF8StringHandle(pchName)) { 81 return NativeMethods.ISteamUserStats_SetAchievement(CSteamAPIContext.GetSteamUserStats(), pchName2); 82 } 83 } 84 85 public static bool ClearAchievement(string pchName) { 86 InteropHelp.TestIfAvailableClient(); 87 using (var pchName2 = new InteropHelp.UTF8StringHandle(pchName)) { 88 return NativeMethods.ISteamUserStats_ClearAchievement(CSteamAPIContext.GetSteamUserStats(), pchName2); 89 } 90 } 91 92 /// <summary> 93 /// <para> Get the achievement status, and the time it was unlocked if unlocked.</para> 94 /// <para> If the return value is true, but the unlock time is zero, that means it was unlocked before Steam</para> 95 /// <para> began tracking achievement unlock times (December 2009). Time is seconds since January 1, 1970.</para> 96 /// </summary> 97 public static bool GetAchievementAndUnlockTime(string pchName, out bool pbAchieved, out uint punUnlockTime) { 98 InteropHelp.TestIfAvailableClient(); 99 using (var pchName2 = new InteropHelp.UTF8StringHandle(pchName)) { 100 return NativeMethods.ISteamUserStats_GetAchievementAndUnlockTime(CSteamAPIContext.GetSteamUserStats(), pchName2, out pbAchieved, out punUnlockTime); 101 } 102 } 103 104 /// <summary> 105 /// <para> Store the current data on the server, will get a callback when set</para> 106 /// <para> And one callback for every new achievement</para> 107 /// <para> If the callback has a result of k_EResultInvalidParam, one or more stats</para> 108 /// <para> uploaded has been rejected, either because they broke constraints</para> 109 /// <para> or were out of date. In this case the server sends back updated values.</para> 110 /// <para> The stats should be re-iterated to keep in sync.</para> 111 /// </summary> 112 public static bool StoreStats() { 113 InteropHelp.TestIfAvailableClient(); 114 return NativeMethods.ISteamUserStats_StoreStats(CSteamAPIContext.GetSteamUserStats()); 115 } 116 117 /// <summary> 118 /// <para> Achievement / GroupAchievement metadata</para> 119 /// <para> Gets the icon of the achievement, which is a handle to be used in ISteamUtils::GetImageRGBA(), or 0 if none set.</para> 120 /// <para> A return value of 0 may indicate we are still fetching data, and you can wait for the UserAchievementIconFetched_t callback</para> 121 /// <para> which will notify you when the bits are ready. If the callback still returns zero, then there is no image set for the</para> 122 /// <para> specified achievement.</para> 123 /// </summary> 124 public static int GetAchievementIcon(string pchName) { 125 InteropHelp.TestIfAvailableClient(); 126 using (var pchName2 = new InteropHelp.UTF8StringHandle(pchName)) { 127 return NativeMethods.ISteamUserStats_GetAchievementIcon(CSteamAPIContext.GetSteamUserStats(), pchName2); 128 } 129 } 130 131 /// <summary> 132 /// <para> Get general attributes for an achievement. Accepts the following keys:</para> 133 /// <para> - "name" and "desc" for retrieving the localized achievement name and description (returned in UTF8)</para> 134 /// <para> - "hidden" for retrieving if an achievement is hidden (returns "0" when not hidden, "1" when hidden)</para> 135 /// </summary> 136 public static string GetAchievementDisplayAttribute(string pchName, string pchKey) { 137 InteropHelp.TestIfAvailableClient(); 138 using (var pchName2 = new InteropHelp.UTF8StringHandle(pchName)) 139 using (var pchKey2 = new InteropHelp.UTF8StringHandle(pchKey)) { 140 return InteropHelp.PtrToStringUTF8(NativeMethods.ISteamUserStats_GetAchievementDisplayAttribute(CSteamAPIContext.GetSteamUserStats(), pchName2, pchKey2)); 141 } 142 } 143 144 /// <summary> 145 /// <para> Achievement progress - triggers an AchievementProgress callback, that is all.</para> 146 /// <para> Calling this w/ N out of N progress will NOT set the achievement, the game must still do that.</para> 147 /// </summary> 148 public static bool IndicateAchievementProgress(string pchName, uint nCurProgress, uint nMaxProgress) { 149 InteropHelp.TestIfAvailableClient(); 150 using (var pchName2 = new InteropHelp.UTF8StringHandle(pchName)) { 151 return NativeMethods.ISteamUserStats_IndicateAchievementProgress(CSteamAPIContext.GetSteamUserStats(), pchName2, nCurProgress, nMaxProgress); 152 } 153 } 154 155 /// <summary> 156 /// <para> Used for iterating achievements. In general games should not need these functions because they should have a</para> 157 /// <para> list of existing achievements compiled into them</para> 158 /// </summary> 159 public static uint GetNumAchievements() { 160 InteropHelp.TestIfAvailableClient(); 161 return NativeMethods.ISteamUserStats_GetNumAchievements(CSteamAPIContext.GetSteamUserStats()); 162 } 163 164 /// <summary> 165 /// <para> Get achievement name iAchievement in [0,GetNumAchievements)</para> 166 /// </summary> 167 public static string GetAchievementName(uint iAchievement) { 168 InteropHelp.TestIfAvailableClient(); 169 return InteropHelp.PtrToStringUTF8(NativeMethods.ISteamUserStats_GetAchievementName(CSteamAPIContext.GetSteamUserStats(), iAchievement)); 170 } 171 172 /// <summary> 173 /// <para> Friends stats & achievements</para> 174 /// <para> downloads stats for the user</para> 175 /// <para> returns a UserStatsReceived_t received when completed</para> 176 /// <para> if the other user has no stats, UserStatsReceived_t.m_eResult will be set to k_EResultFail</para> 177 /// <para> these stats won't be auto-updated; you'll need to call RequestUserStats() again to refresh any data</para> 178 /// </summary> 179 public static SteamAPICall_t RequestUserStats(CSteamID steamIDUser) { 180 InteropHelp.TestIfAvailableClient(); 181 return (SteamAPICall_t)NativeMethods.ISteamUserStats_RequestUserStats(CSteamAPIContext.GetSteamUserStats(), steamIDUser); 182 } 183 184 /// <summary> 185 /// <para> requests stat information for a user, usable after a successful call to RequestUserStats()</para> 186 /// </summary> 187 public static bool GetUserStat(CSteamID steamIDUser, string pchName, out int pData) { 188 InteropHelp.TestIfAvailableClient(); 189 using (var pchName2 = new InteropHelp.UTF8StringHandle(pchName)) { 190 return NativeMethods.ISteamUserStats_GetUserStat(CSteamAPIContext.GetSteamUserStats(), steamIDUser, pchName2, out pData); 191 } 192 } 193 194 public static bool GetUserStat(CSteamID steamIDUser, string pchName, out float pData) { 195 InteropHelp.TestIfAvailableClient(); 196 using (var pchName2 = new InteropHelp.UTF8StringHandle(pchName)) { 197 return NativeMethods.ISteamUserStats_GetUserStat0(CSteamAPIContext.GetSteamUserStats(), steamIDUser, pchName2, out pData); 198 } 199 } 200 201 public static bool GetUserAchievement(CSteamID steamIDUser, string pchName, out bool pbAchieved) { 202 InteropHelp.TestIfAvailableClient(); 203 using (var pchName2 = new InteropHelp.UTF8StringHandle(pchName)) { 204 return NativeMethods.ISteamUserStats_GetUserAchievement(CSteamAPIContext.GetSteamUserStats(), steamIDUser, pchName2, out pbAchieved); 205 } 206 } 207 208 /// <summary> 209 /// <para> See notes for GetAchievementAndUnlockTime above</para> 210 /// </summary> 211 public static bool GetUserAchievementAndUnlockTime(CSteamID steamIDUser, string pchName, out bool pbAchieved, out uint punUnlockTime) { 212 InteropHelp.TestIfAvailableClient(); 213 using (var pchName2 = new InteropHelp.UTF8StringHandle(pchName)) { 214 return NativeMethods.ISteamUserStats_GetUserAchievementAndUnlockTime(CSteamAPIContext.GetSteamUserStats(), steamIDUser, pchName2, out pbAchieved, out punUnlockTime); 215 } 216 } 217 218 /// <summary> 219 /// <para> Reset stats</para> 220 /// </summary> 221 public static bool ResetAllStats(bool bAchievementsToo) { 222 InteropHelp.TestIfAvailableClient(); 223 return NativeMethods.ISteamUserStats_ResetAllStats(CSteamAPIContext.GetSteamUserStats(), bAchievementsToo); 224 } 225 226 /// <summary> 227 /// <para> Leaderboard functions</para> 228 /// <para> asks the Steam back-end for a leaderboard by name, and will create it if it's not yet</para> 229 /// <para> This call is asynchronous, with the result returned in LeaderboardFindResult_t</para> 230 /// </summary> 231 public static SteamAPICall_t FindOrCreateLeaderboard(string pchLeaderboardName, ELeaderboardSortMethod eLeaderboardSortMethod, ELeaderboardDisplayType eLeaderboardDisplayType) { 232 InteropHelp.TestIfAvailableClient(); 233 using (var pchLeaderboardName2 = new InteropHelp.UTF8StringHandle(pchLeaderboardName)) { 234 return (SteamAPICall_t)NativeMethods.ISteamUserStats_FindOrCreateLeaderboard(CSteamAPIContext.GetSteamUserStats(), pchLeaderboardName2, eLeaderboardSortMethod, eLeaderboardDisplayType); 235 } 236 } 237 238 /// <summary> 239 /// <para> as above, but won't create the leaderboard if it's not found</para> 240 /// <para> This call is asynchronous, with the result returned in LeaderboardFindResult_t</para> 241 /// </summary> 242 public static SteamAPICall_t FindLeaderboard(string pchLeaderboardName) { 243 InteropHelp.TestIfAvailableClient(); 244 using (var pchLeaderboardName2 = new InteropHelp.UTF8StringHandle(pchLeaderboardName)) { 245 return (SteamAPICall_t)NativeMethods.ISteamUserStats_FindLeaderboard(CSteamAPIContext.GetSteamUserStats(), pchLeaderboardName2); 246 } 247 } 248 249 /// <summary> 250 /// <para> returns the name of a leaderboard</para> 251 /// </summary> 252 public static string GetLeaderboardName(SteamLeaderboard_t hSteamLeaderboard) { 253 InteropHelp.TestIfAvailableClient(); 254 return InteropHelp.PtrToStringUTF8(NativeMethods.ISteamUserStats_GetLeaderboardName(CSteamAPIContext.GetSteamUserStats(), hSteamLeaderboard)); 255 } 256 257 /// <summary> 258 /// <para> returns the total number of entries in a leaderboard, as of the last request</para> 259 /// </summary> 260 public static int GetLeaderboardEntryCount(SteamLeaderboard_t hSteamLeaderboard) { 261 InteropHelp.TestIfAvailableClient(); 262 return NativeMethods.ISteamUserStats_GetLeaderboardEntryCount(CSteamAPIContext.GetSteamUserStats(), hSteamLeaderboard); 263 } 264 265 /// <summary> 266 /// <para> returns the sort method of the leaderboard</para> 267 /// </summary> 268 public static ELeaderboardSortMethod GetLeaderboardSortMethod(SteamLeaderboard_t hSteamLeaderboard) { 269 InteropHelp.TestIfAvailableClient(); 270 return NativeMethods.ISteamUserStats_GetLeaderboardSortMethod(CSteamAPIContext.GetSteamUserStats(), hSteamLeaderboard); 271 } 272 273 /// <summary> 274 /// <para> returns the display type of the leaderboard</para> 275 /// </summary> 276 public static ELeaderboardDisplayType GetLeaderboardDisplayType(SteamLeaderboard_t hSteamLeaderboard) { 277 InteropHelp.TestIfAvailableClient(); 278 return NativeMethods.ISteamUserStats_GetLeaderboardDisplayType(CSteamAPIContext.GetSteamUserStats(), hSteamLeaderboard); 279 } 280 281 /// <summary> 282 /// <para> Asks the Steam back-end for a set of rows in the leaderboard.</para> 283 /// <para> This call is asynchronous, with the result returned in LeaderboardScoresDownloaded_t</para> 284 /// <para> LeaderboardScoresDownloaded_t will contain a handle to pull the results from GetDownloadedLeaderboardEntries() (below)</para> 285 /// <para> You can ask for more entries than exist, and it will return as many as do exist.</para> 286 /// <para> k_ELeaderboardDataRequestGlobal requests rows in the leaderboard from the full table, with nRangeStart & nRangeEnd in the range [1, TotalEntries]</para> 287 /// <para> k_ELeaderboardDataRequestGlobalAroundUser requests rows around the current user, nRangeStart being negate</para> 288 /// <para> e.g. DownloadLeaderboardEntries( hLeaderboard, k_ELeaderboardDataRequestGlobalAroundUser, -3, 3 ) will return 7 rows, 3 before the user, 3 after</para> 289 /// <para> k_ELeaderboardDataRequestFriends requests all the rows for friends of the current user</para> 290 /// </summary> 291 public static SteamAPICall_t DownloadLeaderboardEntries(SteamLeaderboard_t hSteamLeaderboard, ELeaderboardDataRequest eLeaderboardDataRequest, int nRangeStart, int nRangeEnd) { 292 InteropHelp.TestIfAvailableClient(); 293 return (SteamAPICall_t)NativeMethods.ISteamUserStats_DownloadLeaderboardEntries(CSteamAPIContext.GetSteamUserStats(), hSteamLeaderboard, eLeaderboardDataRequest, nRangeStart, nRangeEnd); 294 } 295 296 /// <summary> 297 /// <para> as above, but downloads leaderboard entries for an arbitrary set of users - ELeaderboardDataRequest is k_ELeaderboardDataRequestUsers</para> 298 /// <para> if a user doesn't have a leaderboard entry, they won't be included in the result</para> 299 /// <para> a max of 100 users can be downloaded at a time, with only one outstanding call at a time</para> 300 /// </summary> 301 public static SteamAPICall_t DownloadLeaderboardEntriesForUsers(SteamLeaderboard_t hSteamLeaderboard, CSteamID[] prgUsers, int cUsers) { 302 InteropHelp.TestIfAvailableClient(); 303 return (SteamAPICall_t)NativeMethods.ISteamUserStats_DownloadLeaderboardEntriesForUsers(CSteamAPIContext.GetSteamUserStats(), hSteamLeaderboard, prgUsers, cUsers); 304 } 305 306 /// <summary> 307 /// <para> Returns data about a single leaderboard entry</para> 308 /// <para> use a for loop from 0 to LeaderboardScoresDownloaded_t::m_cEntryCount to get all the downloaded entries</para> 309 /// <para> e.g.</para> 310 /// <para> void OnLeaderboardScoresDownloaded( LeaderboardScoresDownloaded_t *pLeaderboardScoresDownloaded )</para> 311 /// <para> {</para> 312 /// <para> for ( int index = 0; index < pLeaderboardScoresDownloaded->m_cEntryCount; index++ )</para> 313 /// <para> {</para> 314 /// <para> LeaderboardEntry_t leaderboardEntry;</para> 315 /// <para> int32 details[3]; // we know this is how many we've stored previously</para> 316 /// <para> GetDownloadedLeaderboardEntry( pLeaderboardScoresDownloaded->m_hSteamLeaderboardEntries, index, &leaderboardEntry, details, 3 );</para> 317 /// <para> assert( leaderboardEntry.m_cDetails == 3 );</para> 318 /// <para> ...</para> 319 /// <para> }</para> 320 /// <para> once you've accessed all the entries, the data will be free'd, and the SteamLeaderboardEntries_t handle will become invalid</para> 321 /// </summary> 322 public static bool GetDownloadedLeaderboardEntry(SteamLeaderboardEntries_t hSteamLeaderboardEntries, int index, out LeaderboardEntry_t pLeaderboardEntry, int[] pDetails, int cDetailsMax) { 323 InteropHelp.TestIfAvailableClient(); 324 return NativeMethods.ISteamUserStats_GetDownloadedLeaderboardEntry(CSteamAPIContext.GetSteamUserStats(), hSteamLeaderboardEntries, index, out pLeaderboardEntry, pDetails, cDetailsMax); 325 } 326 327 /// <summary> 328 /// <para> Uploads a user score to the Steam back-end.</para> 329 /// <para> This call is asynchronous, with the result returned in LeaderboardScoreUploaded_t</para> 330 /// <para> Details are extra game-defined information regarding how the user got that score</para> 331 /// <para> pScoreDetails points to an array of int32's, cScoreDetailsCount is the number of int32's in the list</para> 332 /// </summary> 333 public static SteamAPICall_t UploadLeaderboardScore(SteamLeaderboard_t hSteamLeaderboard, ELeaderboardUploadScoreMethod eLeaderboardUploadScoreMethod, int nScore, int[] pScoreDetails, int cScoreDetailsCount) { 334 InteropHelp.TestIfAvailableClient(); 335 return (SteamAPICall_t)NativeMethods.ISteamUserStats_UploadLeaderboardScore(CSteamAPIContext.GetSteamUserStats(), hSteamLeaderboard, eLeaderboardUploadScoreMethod, nScore, pScoreDetails, cScoreDetailsCount); 336 } 337 338 /// <summary> 339 /// <para> Attaches a piece of user generated content the user's entry on a leaderboard.</para> 340 /// <para> hContent is a handle to a piece of user generated content that was shared using ISteamUserRemoteStorage::FileShare().</para> 341 /// <para> This call is asynchronous, with the result returned in LeaderboardUGCSet_t.</para> 342 /// </summary> 343 public static SteamAPICall_t AttachLeaderboardUGC(SteamLeaderboard_t hSteamLeaderboard, UGCHandle_t hUGC) { 344 InteropHelp.TestIfAvailableClient(); 345 return (SteamAPICall_t)NativeMethods.ISteamUserStats_AttachLeaderboardUGC(CSteamAPIContext.GetSteamUserStats(), hSteamLeaderboard, hUGC); 346 } 347 348 /// <summary> 349 /// <para> Retrieves the number of players currently playing your game (online + offline)</para> 350 /// <para> This call is asynchronous, with the result returned in NumberOfCurrentPlayers_t</para> 351 /// </summary> 352 public static SteamAPICall_t GetNumberOfCurrentPlayers() { 353 InteropHelp.TestIfAvailableClient(); 354 return (SteamAPICall_t)NativeMethods.ISteamUserStats_GetNumberOfCurrentPlayers(CSteamAPIContext.GetSteamUserStats()); 355 } 356 357 /// <summary> 358 /// <para> Requests that Steam fetch data on the percentage of players who have received each achievement</para> 359 /// <para> for the game globally.</para> 360 /// <para> This call is asynchronous, with the result returned in GlobalAchievementPercentagesReady_t.</para> 361 /// </summary> 362 public static SteamAPICall_t RequestGlobalAchievementPercentages() { 363 InteropHelp.TestIfAvailableClient(); 364 return (SteamAPICall_t)NativeMethods.ISteamUserStats_RequestGlobalAchievementPercentages(CSteamAPIContext.GetSteamUserStats()); 365 } 366 367 /// <summary> 368 /// <para> Get the info on the most achieved achievement for the game, returns an iterator index you can use to fetch</para> 369 /// <para> the next most achieved afterwards. Will return -1 if there is no data on achievement</para> 370 /// <para> percentages (ie, you haven't called RequestGlobalAchievementPercentages and waited on the callback).</para> 371 /// </summary> 372 public static int GetMostAchievedAchievementInfo(out string pchName, uint unNameBufLen, out float pflPercent, out bool pbAchieved) { 373 InteropHelp.TestIfAvailableClient(); 374 IntPtr pchName2 = Marshal.AllocHGlobal((int)unNameBufLen); 375 int ret = NativeMethods.ISteamUserStats_GetMostAchievedAchievementInfo(CSteamAPIContext.GetSteamUserStats(), pchName2, unNameBufLen, out pflPercent, out pbAchieved); 376 pchName = ret != -1 ? InteropHelp.PtrToStringUTF8(pchName2) : null; 377 Marshal.FreeHGlobal(pchName2); 378 return ret; 379 } 380 381 /// <summary> 382 /// <para> Get the info on the next most achieved achievement for the game. Call this after GetMostAchievedAchievementInfo or another</para> 383 /// <para> GetNextMostAchievedAchievementInfo call passing the iterator from the previous call. Returns -1 after the last</para> 384 /// <para> achievement has been iterated.</para> 385 /// </summary> 386 public static int GetNextMostAchievedAchievementInfo(int iIteratorPrevious, out string pchName, uint unNameBufLen, out float pflPercent, out bool pbAchieved) { 387 InteropHelp.TestIfAvailableClient(); 388 IntPtr pchName2 = Marshal.AllocHGlobal((int)unNameBufLen); 389 int ret = NativeMethods.ISteamUserStats_GetNextMostAchievedAchievementInfo(CSteamAPIContext.GetSteamUserStats(), iIteratorPrevious, pchName2, unNameBufLen, out pflPercent, out pbAchieved); 390 pchName = ret != -1 ? InteropHelp.PtrToStringUTF8(pchName2) : null; 391 Marshal.FreeHGlobal(pchName2); 392 return ret; 393 } 394 395 /// <summary> 396 /// <para> Returns the percentage of users who have achieved the specified achievement.</para> 397 /// </summary> 398 public static bool GetAchievementAchievedPercent(string pchName, out float pflPercent) { 399 InteropHelp.TestIfAvailableClient(); 400 using (var pchName2 = new InteropHelp.UTF8StringHandle(pchName)) { 401 return NativeMethods.ISteamUserStats_GetAchievementAchievedPercent(CSteamAPIContext.GetSteamUserStats(), pchName2, out pflPercent); 402 } 403 } 404 405 /// <summary> 406 /// <para> Requests global stats data, which is available for stats marked as "aggregated".</para> 407 /// <para> This call is asynchronous, with the results returned in GlobalStatsReceived_t.</para> 408 /// <para> nHistoryDays specifies how many days of day-by-day history to retrieve in addition</para> 409 /// <para> to the overall totals. The limit is 60.</para> 410 /// </summary> 411 public static SteamAPICall_t RequestGlobalStats(int nHistoryDays) { 412 InteropHelp.TestIfAvailableClient(); 413 return (SteamAPICall_t)NativeMethods.ISteamUserStats_RequestGlobalStats(CSteamAPIContext.GetSteamUserStats(), nHistoryDays); 414 } 415 416 /// <summary> 417 /// <para> Gets the lifetime totals for an aggregated stat</para> 418 /// </summary> 419 public static bool GetGlobalStat(string pchStatName, out long pData) { 420 InteropHelp.TestIfAvailableClient(); 421 using (var pchStatName2 = new InteropHelp.UTF8StringHandle(pchStatName)) { 422 return NativeMethods.ISteamUserStats_GetGlobalStat(CSteamAPIContext.GetSteamUserStats(), pchStatName2, out pData); 423 } 424 } 425 426 public static bool GetGlobalStat(string pchStatName, out double pData) { 427 InteropHelp.TestIfAvailableClient(); 428 using (var pchStatName2 = new InteropHelp.UTF8StringHandle(pchStatName)) { 429 return NativeMethods.ISteamUserStats_GetGlobalStat0(CSteamAPIContext.GetSteamUserStats(), pchStatName2, out pData); 430 } 431 } 432 433 /// <summary> 434 /// <para> Gets history for an aggregated stat. pData will be filled with daily values, starting with today.</para> 435 /// <para> So when called, pData[0] will be today, pData[1] will be yesterday, and pData[2] will be two days ago,</para> 436 /// <para> etc. cubData is the size in bytes of the pubData buffer. Returns the number of</para> 437 /// <para> elements actually set.</para> 438 /// </summary> 439 public static int GetGlobalStatHistory(string pchStatName, long[] pData, uint cubData) { 440 InteropHelp.TestIfAvailableClient(); 441 using (var pchStatName2 = new InteropHelp.UTF8StringHandle(pchStatName)) { 442 return NativeMethods.ISteamUserStats_GetGlobalStatHistory(CSteamAPIContext.GetSteamUserStats(), pchStatName2, pData, cubData); 443 } 444 } 445 446 public static int GetGlobalStatHistory(string pchStatName, double[] pData, uint cubData) { 447 InteropHelp.TestIfAvailableClient(); 448 using (var pchStatName2 = new InteropHelp.UTF8StringHandle(pchStatName)) { 449 return NativeMethods.ISteamUserStats_GetGlobalStatHistory0(CSteamAPIContext.GetSteamUserStats(), pchStatName2, pData, cubData); 450 } 451 } 452 #if _PS3 453 /// <summary> 454 /// <para> Call to kick off installation of the PS3 trophies. This call is asynchronous, and the results will be returned in a PS3TrophiesInstalled_t</para> 455 /// <para> callback.</para> 456 /// </summary> 457 public static bool InstallPS3Trophies() { 458 InteropHelp.TestIfAvailableClient(); 459 return NativeMethods.ISteamUserStats_InstallPS3Trophies(CSteamAPIContext.GetSteamUserStats()); 460 } 461 462 /// <summary> 463 /// <para> Returns the amount of space required at boot to install trophies. This value can be used when comparing the amount of space needed</para> 464 /// <para> by the game to the available space value passed to the game at boot. The value is set during InstallPS3Trophies().</para> 465 /// </summary> 466 public static ulong GetTrophySpaceRequiredBeforeInstall() { 467 InteropHelp.TestIfAvailableClient(); 468 return NativeMethods.ISteamUserStats_GetTrophySpaceRequiredBeforeInstall(CSteamAPIContext.GetSteamUserStats()); 469 } 470 471 /// <summary> 472 /// <para> On PS3, user stats & achievement progress through Steam must be stored with the user's saved game data.</para> 473 /// <para> At startup, before calling RequestCurrentStats(), you must pass the user's stats data to Steam via this method.</para> 474 /// <para> If you do not have any user data, call this function with pvData = NULL and cubData = 0</para> 475 /// </summary> 476 public static bool SetUserStatsData(IntPtr pvData, uint cubData) { 477 InteropHelp.TestIfAvailableClient(); 478 return NativeMethods.ISteamUserStats_SetUserStatsData(CSteamAPIContext.GetSteamUserStats(), pvData, cubData); 479 } 480 481 /// <summary> 482 /// <para> Call to get the user's current stats data. You should retrieve this data after receiving successful UserStatsReceived_t & UserStatsStored_t</para> 483 /// <para> callbacks, and store the data with the user's save game data. You can call this method with pvData = NULL and cubData = 0 to get the required</para> 484 /// <para> buffer size.</para> 485 /// </summary> 486 public static bool GetUserStatsData(IntPtr pvData, uint cubData, out uint pcubWritten) { 487 InteropHelp.TestIfAvailableClient(); 488 return NativeMethods.ISteamUserStats_GetUserStatsData(CSteamAPIContext.GetSteamUserStats(), pvData, cubData, out pcubWritten); 489 } 490 #endif 491 } 492 } 493 494 #endif // !DISABLESTEAMWORKS