isteamuser.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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 SteamUser {
  14. /// <summary>
  15. /// <para> returns the HSteamUser this interface represents</para>
  16. /// <para> this is only used internally by the API, and by a few select interfaces that support multi-user</para>
  17. /// </summary>
  18. public static HSteamUser GetHSteamUser() {
  19. InteropHelp.TestIfAvailableClient();
  20. return (HSteamUser)NativeMethods.ISteamUser_GetHSteamUser(CSteamAPIContext.GetSteamUser());
  21. }
  22. /// <summary>
  23. /// <para> returns true if the Steam client current has a live connection to the Steam servers.</para>
  24. /// <para> If false, it means there is no active connection due to either a networking issue on the local machine, or the Steam server is down/busy.</para>
  25. /// <para> The Steam client will automatically be trying to recreate the connection as often as possible.</para>
  26. /// </summary>
  27. public static bool BLoggedOn() {
  28. InteropHelp.TestIfAvailableClient();
  29. return NativeMethods.ISteamUser_BLoggedOn(CSteamAPIContext.GetSteamUser());
  30. }
  31. /// <summary>
  32. /// <para> returns the CSteamID of the account currently logged into the Steam client</para>
  33. /// <para> a CSteamID is a unique identifier for an account, and used to differentiate users in all parts of the Steamworks API</para>
  34. /// </summary>
  35. public static CSteamID GetSteamID() {
  36. InteropHelp.TestIfAvailableClient();
  37. return (CSteamID)NativeMethods.ISteamUser_GetSteamID(CSteamAPIContext.GetSteamUser());
  38. }
  39. /// <summary>
  40. /// <para> Multiplayer Authentication functions</para>
  41. /// <para> InitiateGameConnection() starts the state machine for authenticating the game client with the game server</para>
  42. /// <para> It is the client portion of a three-way handshake between the client, the game server, and the steam servers</para>
  43. /// <para> Parameters:</para>
  44. /// <para> void *pAuthBlob - a pointer to empty memory that will be filled in with the authentication token.</para>
  45. /// <para> int cbMaxAuthBlob - the number of bytes of allocated memory in pBlob. Should be at least 2048 bytes.</para>
  46. /// <para> CSteamID steamIDGameServer - the steamID of the game server, received from the game server by the client</para>
  47. /// <para> CGameID gameID - the ID of the current game. For games without mods, this is just CGameID( &lt;appID&gt; )</para>
  48. /// <para> uint32 unIPServer, uint16 usPortServer - the IP address of the game server</para>
  49. /// <para> bool bSecure - whether or not the client thinks that the game server is reporting itself as secure (i.e. VAC is running)</para>
  50. /// <para> return value - returns the number of bytes written to pBlob. If the return is 0, then the buffer passed in was too small, and the call has failed</para>
  51. /// <para> The contents of pBlob should then be sent to the game server, for it to use to complete the authentication process.</para>
  52. /// </summary>
  53. public static int InitiateGameConnection(byte[] pAuthBlob, int cbMaxAuthBlob, CSteamID steamIDGameServer, uint unIPServer, ushort usPortServer, bool bSecure) {
  54. InteropHelp.TestIfAvailableClient();
  55. return NativeMethods.ISteamUser_InitiateGameConnection(CSteamAPIContext.GetSteamUser(), pAuthBlob, cbMaxAuthBlob, steamIDGameServer, unIPServer, usPortServer, bSecure);
  56. }
  57. /// <summary>
  58. /// <para> notify of disconnect</para>
  59. /// <para> needs to occur when the game client leaves the specified game server, needs to match with the InitiateGameConnection() call</para>
  60. /// </summary>
  61. public static void TerminateGameConnection(uint unIPServer, ushort usPortServer) {
  62. InteropHelp.TestIfAvailableClient();
  63. NativeMethods.ISteamUser_TerminateGameConnection(CSteamAPIContext.GetSteamUser(), unIPServer, usPortServer);
  64. }
  65. /// <summary>
  66. /// <para> Legacy functions</para>
  67. /// <para> used by only a few games to track usage events</para>
  68. /// </summary>
  69. public static void TrackAppUsageEvent(CGameID gameID, int eAppUsageEvent, string pchExtraInfo = "") {
  70. InteropHelp.TestIfAvailableClient();
  71. using (var pchExtraInfo2 = new InteropHelp.UTF8StringHandle(pchExtraInfo)) {
  72. NativeMethods.ISteamUser_TrackAppUsageEvent(CSteamAPIContext.GetSteamUser(), gameID, eAppUsageEvent, pchExtraInfo2);
  73. }
  74. }
  75. /// <summary>
  76. /// <para> get the local storage folder for current Steam account to write application data, e.g. save games, configs etc.</para>
  77. /// <para> this will usually be something like "C:\Progam Files\Steam\userdata\&lt;SteamID&gt;\&lt;AppID&gt;\local"</para>
  78. /// </summary>
  79. public static bool GetUserDataFolder(out string pchBuffer, int cubBuffer) {
  80. InteropHelp.TestIfAvailableClient();
  81. IntPtr pchBuffer2 = Marshal.AllocHGlobal(cubBuffer);
  82. bool ret = NativeMethods.ISteamUser_GetUserDataFolder(CSteamAPIContext.GetSteamUser(), pchBuffer2, cubBuffer);
  83. pchBuffer = ret ? InteropHelp.PtrToStringUTF8(pchBuffer2) : null;
  84. Marshal.FreeHGlobal(pchBuffer2);
  85. return ret;
  86. }
  87. /// <summary>
  88. /// <para> Starts voice recording. Once started, use GetVoice() to get the data</para>
  89. /// </summary>
  90. public static void StartVoiceRecording() {
  91. InteropHelp.TestIfAvailableClient();
  92. NativeMethods.ISteamUser_StartVoiceRecording(CSteamAPIContext.GetSteamUser());
  93. }
  94. /// <summary>
  95. /// <para> Stops voice recording. Because people often release push-to-talk keys early, the system will keep recording for</para>
  96. /// <para> a little bit after this function is called. GetVoice() should continue to be called until it returns</para>
  97. /// <para> k_eVoiceResultNotRecording</para>
  98. /// </summary>
  99. public static void StopVoiceRecording() {
  100. InteropHelp.TestIfAvailableClient();
  101. NativeMethods.ISteamUser_StopVoiceRecording(CSteamAPIContext.GetSteamUser());
  102. }
  103. /// <summary>
  104. /// <para> Determine the size of captured audio data that is available from GetVoice.</para>
  105. /// <para> Most applications will only use compressed data and should ignore the other</para>
  106. /// <para> parameters, which exist primarily for backwards compatibility. See comments</para>
  107. /// <para> below for further explanation of "uncompressed" data.</para>
  108. /// </summary>
  109. public static EVoiceResult GetAvailableVoice(out uint pcbCompressed) {
  110. InteropHelp.TestIfAvailableClient();
  111. return NativeMethods.ISteamUser_GetAvailableVoice(CSteamAPIContext.GetSteamUser(), out pcbCompressed, IntPtr.Zero, 0);
  112. }
  113. /// <summary>
  114. /// <para> ---------------------------------------------------------------------------</para>
  115. /// <para> NOTE: "uncompressed" audio is a deprecated feature and should not be used</para>
  116. /// <para> by most applications. It is raw single-channel 16-bit PCM wave data which</para>
  117. /// <para> may have been run through preprocessing filters and/or had silence removed,</para>
  118. /// <para> so the uncompressed audio could have a shorter duration than you expect.</para>
  119. /// <para> There may be no data at all during long periods of silence. Also, fetching</para>
  120. /// <para> uncompressed audio will cause GetVoice to discard any leftover compressed</para>
  121. /// <para> audio, so you must fetch both types at once. Finally, GetAvailableVoice is</para>
  122. /// <para> not precisely accurate when the uncompressed size is requested. So if you</para>
  123. /// <para> really need to use uncompressed audio, you should call GetVoice frequently</para>
  124. /// <para> with two very large (20kb+) output buffers instead of trying to allocate</para>
  125. /// <para> perfectly-sized buffers. But most applications should ignore all of these</para>
  126. /// <para> details and simply leave the "uncompressed" parameters as NULL/zero.</para>
  127. /// <para> ---------------------------------------------------------------------------</para>
  128. /// <para> Read captured audio data from the microphone buffer. This should be called</para>
  129. /// <para> at least once per frame, and preferably every few milliseconds, to keep the</para>
  130. /// <para> microphone input delay as low as possible. Most applications will only use</para>
  131. /// <para> compressed data and should pass NULL/zero for the "uncompressed" parameters.</para>
  132. /// <para> Compressed data can be transmitted by your application and decoded into raw</para>
  133. /// <para> using the DecompressVoice function below.</para>
  134. /// </summary>
  135. public static EVoiceResult GetVoice(bool bWantCompressed, byte[] pDestBuffer, uint cbDestBufferSize, out uint nBytesWritten) {
  136. InteropHelp.TestIfAvailableClient();
  137. return NativeMethods.ISteamUser_GetVoice(CSteamAPIContext.GetSteamUser(), bWantCompressed, pDestBuffer, cbDestBufferSize, out nBytesWritten, false, IntPtr.Zero, 0, IntPtr.Zero, 0);
  138. }
  139. /// <summary>
  140. /// <para> Decodes the compressed voice data returned by GetVoice. The output data is</para>
  141. /// <para> raw single-channel 16-bit PCM audio. The decoder supports any sample rate</para>
  142. /// <para> from 11025 to 48000; see GetVoiceOptimalSampleRate() below for details.</para>
  143. /// <para> If the output buffer is not large enough, then *nBytesWritten will be set</para>
  144. /// <para> to the required buffer size, and k_EVoiceResultBufferTooSmall is returned.</para>
  145. /// <para> It is suggested to start with a 20kb buffer and reallocate as necessary.</para>
  146. /// </summary>
  147. public static EVoiceResult DecompressVoice(byte[] pCompressed, uint cbCompressed, byte[] pDestBuffer, uint cbDestBufferSize, out uint nBytesWritten, uint nDesiredSampleRate) {
  148. InteropHelp.TestIfAvailableClient();
  149. return NativeMethods.ISteamUser_DecompressVoice(CSteamAPIContext.GetSteamUser(), pCompressed, cbCompressed, pDestBuffer, cbDestBufferSize, out nBytesWritten, nDesiredSampleRate);
  150. }
  151. /// <summary>
  152. /// <para> This returns the native sample rate of the Steam voice decompressor; using</para>
  153. /// <para> this sample rate for DecompressVoice will perform the least CPU processing.</para>
  154. /// <para> However, the final audio quality will depend on how well the audio device</para>
  155. /// <para> (and/or your application's audio output SDK) deals with lower sample rates.</para>
  156. /// <para> You may find that you get the best audio output quality when you ignore</para>
  157. /// <para> this function and use the native sample rate of your audio output device,</para>
  158. /// <para> which is usually 48000 or 44100.</para>
  159. /// </summary>
  160. public static uint GetVoiceOptimalSampleRate() {
  161. InteropHelp.TestIfAvailableClient();
  162. return NativeMethods.ISteamUser_GetVoiceOptimalSampleRate(CSteamAPIContext.GetSteamUser());
  163. }
  164. /// <summary>
  165. /// <para> Retrieve ticket to be sent to the entity who wishes to authenticate you.</para>
  166. /// <para> pcbTicket retrieves the length of the actual ticket.</para>
  167. /// </summary>
  168. public static HAuthTicket GetAuthSessionTicket(byte[] pTicket, int cbMaxTicket, out uint pcbTicket) {
  169. InteropHelp.TestIfAvailableClient();
  170. return (HAuthTicket)NativeMethods.ISteamUser_GetAuthSessionTicket(CSteamAPIContext.GetSteamUser(), pTicket, cbMaxTicket, out pcbTicket);
  171. }
  172. /// <summary>
  173. /// <para> Authenticate ticket from entity steamID to be sure it is valid and isnt reused</para>
  174. /// <para> Registers for callbacks if the entity goes offline or cancels the ticket ( see ValidateAuthTicketResponse_t callback and EAuthSessionResponse )</para>
  175. /// </summary>
  176. public static EBeginAuthSessionResult BeginAuthSession(byte[] pAuthTicket, int cbAuthTicket, CSteamID steamID) {
  177. InteropHelp.TestIfAvailableClient();
  178. return NativeMethods.ISteamUser_BeginAuthSession(CSteamAPIContext.GetSteamUser(), pAuthTicket, cbAuthTicket, steamID);
  179. }
  180. /// <summary>
  181. /// <para> Stop tracking started by BeginAuthSession - called when no longer playing game with this entity</para>
  182. /// </summary>
  183. public static void EndAuthSession(CSteamID steamID) {
  184. InteropHelp.TestIfAvailableClient();
  185. NativeMethods.ISteamUser_EndAuthSession(CSteamAPIContext.GetSteamUser(), steamID);
  186. }
  187. /// <summary>
  188. /// <para> Cancel auth ticket from GetAuthSessionTicket, called when no longer playing game with the entity you gave the ticket to</para>
  189. /// </summary>
  190. public static void CancelAuthTicket(HAuthTicket hAuthTicket) {
  191. InteropHelp.TestIfAvailableClient();
  192. NativeMethods.ISteamUser_CancelAuthTicket(CSteamAPIContext.GetSteamUser(), hAuthTicket);
  193. }
  194. /// <summary>
  195. /// <para> After receiving a user's authentication data, and passing it to BeginAuthSession, use this function</para>
  196. /// <para> to determine if the user owns downloadable content specified by the provided AppID.</para>
  197. /// </summary>
  198. public static EUserHasLicenseForAppResult UserHasLicenseForApp(CSteamID steamID, AppId_t appID) {
  199. InteropHelp.TestIfAvailableClient();
  200. return NativeMethods.ISteamUser_UserHasLicenseForApp(CSteamAPIContext.GetSteamUser(), steamID, appID);
  201. }
  202. /// <summary>
  203. /// <para> returns true if this users looks like they are behind a NAT device. Only valid once the user has connected to steam</para>
  204. /// <para> (i.e a SteamServersConnected_t has been issued) and may not catch all forms of NAT.</para>
  205. /// </summary>
  206. public static bool BIsBehindNAT() {
  207. InteropHelp.TestIfAvailableClient();
  208. return NativeMethods.ISteamUser_BIsBehindNAT(CSteamAPIContext.GetSteamUser());
  209. }
  210. /// <summary>
  211. /// <para> set data to be replicated to friends so that they can join your game</para>
  212. /// <para> CSteamID steamIDGameServer - the steamID of the game server, received from the game server by the client</para>
  213. /// <para> uint32 unIPServer, uint16 usPortServer - the IP address of the game server</para>
  214. /// </summary>
  215. public static void AdvertiseGame(CSteamID steamIDGameServer, uint unIPServer, ushort usPortServer) {
  216. InteropHelp.TestIfAvailableClient();
  217. NativeMethods.ISteamUser_AdvertiseGame(CSteamAPIContext.GetSteamUser(), steamIDGameServer, unIPServer, usPortServer);
  218. }
  219. /// <summary>
  220. /// <para> Requests a ticket encrypted with an app specific shared key</para>
  221. /// <para> pDataToInclude, cbDataToInclude will be encrypted into the ticket</para>
  222. /// <para> ( This is asynchronous, you must wait for the ticket to be completed by the server )</para>
  223. /// </summary>
  224. public static SteamAPICall_t RequestEncryptedAppTicket(byte[] pDataToInclude, int cbDataToInclude) {
  225. InteropHelp.TestIfAvailableClient();
  226. return (SteamAPICall_t)NativeMethods.ISteamUser_RequestEncryptedAppTicket(CSteamAPIContext.GetSteamUser(), pDataToInclude, cbDataToInclude);
  227. }
  228. /// <summary>
  229. /// <para> retrieve a finished ticket</para>
  230. /// </summary>
  231. public static bool GetEncryptedAppTicket(byte[] pTicket, int cbMaxTicket, out uint pcbTicket) {
  232. InteropHelp.TestIfAvailableClient();
  233. return NativeMethods.ISteamUser_GetEncryptedAppTicket(CSteamAPIContext.GetSteamUser(), pTicket, cbMaxTicket, out pcbTicket);
  234. }
  235. /// <summary>
  236. /// <para> Trading Card badges data access</para>
  237. /// <para> if you only have one set of cards, the series will be 1</para>
  238. /// <para> the user has can have two different badges for a series; the regular (max level 5) and the foil (max level 1)</para>
  239. /// </summary>
  240. public static int GetGameBadgeLevel(int nSeries, bool bFoil) {
  241. InteropHelp.TestIfAvailableClient();
  242. return NativeMethods.ISteamUser_GetGameBadgeLevel(CSteamAPIContext.GetSteamUser(), nSeries, bFoil);
  243. }
  244. /// <summary>
  245. /// <para> gets the Steam Level of the user, as shown on their profile</para>
  246. /// </summary>
  247. public static int GetPlayerSteamLevel() {
  248. InteropHelp.TestIfAvailableClient();
  249. return NativeMethods.ISteamUser_GetPlayerSteamLevel(CSteamAPIContext.GetSteamUser());
  250. }
  251. /// <summary>
  252. /// <para> Requests a URL which authenticates an in-game browser for store check-out,</para>
  253. /// <para> and then redirects to the specified URL. As long as the in-game browser</para>
  254. /// <para> accepts and handles session cookies, Steam microtransaction checkout pages</para>
  255. /// <para> will automatically recognize the user instead of presenting a login page.</para>
  256. /// <para> The result of this API call will be a StoreAuthURLResponse_t callback.</para>
  257. /// <para> NOTE: The URL has a very short lifetime to prevent history-snooping attacks,</para>
  258. /// <para> so you should only call this API when you are about to launch the browser,</para>
  259. /// <para> or else immediately navigate to the result URL using a hidden browser window.</para>
  260. /// <para> NOTE 2: The resulting authorization cookie has an expiration time of one day,</para>
  261. /// <para> so it would be a good idea to request and visit a new auth URL every 12 hours.</para>
  262. /// </summary>
  263. public static SteamAPICall_t RequestStoreAuthURL(string pchRedirectURL) {
  264. InteropHelp.TestIfAvailableClient();
  265. using (var pchRedirectURL2 = new InteropHelp.UTF8StringHandle(pchRedirectURL)) {
  266. return (SteamAPICall_t)NativeMethods.ISteamUser_RequestStoreAuthURL(CSteamAPIContext.GetSteamUser(), pchRedirectURL2);
  267. }
  268. }
  269. /// <summary>
  270. /// <para> gets whether the users phone number is verified</para>
  271. /// </summary>
  272. public static bool BIsPhoneVerified() {
  273. InteropHelp.TestIfAvailableClient();
  274. return NativeMethods.ISteamUser_BIsPhoneVerified(CSteamAPIContext.GetSteamUser());
  275. }
  276. /// <summary>
  277. /// <para> gets whether the user has two factor enabled on their account</para>
  278. /// </summary>
  279. public static bool BIsTwoFactorEnabled() {
  280. InteropHelp.TestIfAvailableClient();
  281. return NativeMethods.ISteamUser_BIsTwoFactorEnabled(CSteamAPIContext.GetSteamUser());
  282. }
  283. /// <summary>
  284. /// <para> gets whether the users phone number is identifying</para>
  285. /// </summary>
  286. public static bool BIsPhoneIdentifying() {
  287. InteropHelp.TestIfAvailableClient();
  288. return NativeMethods.ISteamUser_BIsPhoneIdentifying(CSteamAPIContext.GetSteamUser());
  289. }
  290. /// <summary>
  291. /// <para> gets whether the users phone number is awaiting (re)verification</para>
  292. /// </summary>
  293. public static bool BIsPhoneRequiringVerification() {
  294. InteropHelp.TestIfAvailableClient();
  295. return NativeMethods.ISteamUser_BIsPhoneRequiringVerification(CSteamAPIContext.GetSteamUser());
  296. }
  297. public static SteamAPICall_t GetMarketEligibility() {
  298. InteropHelp.TestIfAvailableClient();
  299. return (SteamAPICall_t)NativeMethods.ISteamUser_GetMarketEligibility(CSteamAPIContext.GetSteamUser());
  300. }
  301. /// <summary>
  302. /// <para> Retrieves anti indulgence / duration control for current user</para>
  303. /// </summary>
  304. public static SteamAPICall_t GetDurationControl() {
  305. InteropHelp.TestIfAvailableClient();
  306. return (SteamAPICall_t)NativeMethods.ISteamUser_GetDurationControl(CSteamAPIContext.GetSteamUser());
  307. }
  308. }
  309. }
  310. #endif // !DISABLESTEAMWORKS