isteamuserstats.cs 26 KB

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