Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

310 lines
13 KiB

  1. //====== Copyright � 1996-2008, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: interface to utility functions in Steam
  4. //
  5. //=============================================================================
  6. #ifndef ISTEAMUTILS_H
  7. #define ISTEAMUTILS_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "isteamclient.h"
  12. // Steam API call failure results
  13. enum ESteamAPICallFailure
  14. {
  15. k_ESteamAPICallFailureNone = -1, // no failure
  16. k_ESteamAPICallFailureSteamGone = 0, // the local Steam process has gone away
  17. k_ESteamAPICallFailureNetworkFailure = 1, // the network connection to Steam has been broken, or was already broken
  18. // SteamServersDisconnected_t callback will be sent around the same time
  19. // SteamServersConnected_t will be sent when the client is able to talk to the Steam servers again
  20. k_ESteamAPICallFailureInvalidHandle = 2, // the SteamAPICall_t handle passed in no longer exists
  21. k_ESteamAPICallFailureMismatchedCallback = 3,// GetAPICallResult() was called with the wrong callback type for this API call
  22. };
  23. // Input modes for the Big Picture gamepad text entry
  24. enum EGamepadTextInputMode
  25. {
  26. k_EGamepadTextInputModeNormal = 0,
  27. k_EGamepadTextInputModePassword = 1
  28. };
  29. // Controls number of allowed lines for the Big Picture gamepad text entry
  30. enum EGamepadTextInputLineMode
  31. {
  32. k_EGamepadTextInputLineModeSingleLine = 0,
  33. k_EGamepadTextInputLineModeMultipleLines = 1
  34. };
  35. // function prototype for warning message hook
  36. #if defined( POSIX )
  37. #define __cdecl
  38. #endif
  39. extern "C" typedef void (__cdecl *SteamAPIWarningMessageHook_t)(int, const char *);
  40. //-----------------------------------------------------------------------------
  41. // Purpose: interface to user independent utility functions
  42. //-----------------------------------------------------------------------------
  43. class ISteamUtils
  44. {
  45. public:
  46. // return the number of seconds since the user
  47. virtual uint32 GetSecondsSinceAppActive() = 0;
  48. virtual uint32 GetSecondsSinceComputerActive() = 0;
  49. // the universe this client is connecting to
  50. virtual EUniverse GetConnectedUniverse() = 0;
  51. // Steam server time - in PST, number of seconds since January 1, 1970 (i.e unix time)
  52. virtual uint32 GetServerRealTime() = 0;
  53. // returns the 2 digit ISO 3166-1-alpha-2 format country code this client is running in (as looked up via an IP-to-location database)
  54. // e.g "US" or "UK".
  55. virtual const char *GetIPCountry() = 0;
  56. // returns true if the image exists, and valid sizes were filled out
  57. virtual bool GetImageSize( int iImage, uint32 *pnWidth, uint32 *pnHeight ) = 0;
  58. // returns true if the image exists, and the buffer was successfully filled out
  59. // results are returned in RGBA format
  60. // the destination buffer size should be 4 * height * width * sizeof(char)
  61. virtual bool GetImageRGBA( int iImage, uint8 *pubDest, int nDestBufferSize ) = 0;
  62. // returns the IP of the reporting server for valve - currently only used in Source engine games
  63. virtual bool GetCSERIPPort( uint32 *unIP, uint16 *usPort ) = 0;
  64. // return the amount of battery power left in the current system in % [0..100], 255 for being on AC power
  65. virtual uint8 GetCurrentBatteryPower() = 0;
  66. // returns the appID of the current process
  67. virtual uint32 GetAppID() = 0;
  68. // Sets the position where the overlay instance for the currently calling game should show notifications.
  69. // This position is per-game and if this function is called from outside of a game context it will do nothing.
  70. virtual void SetOverlayNotificationPosition( ENotificationPosition eNotificationPosition ) = 0;
  71. // API asynchronous call results
  72. // can be used directly, but more commonly used via the callback dispatch API (see steam_api.h)
  73. virtual bool IsAPICallCompleted( SteamAPICall_t hSteamAPICall, bool *pbFailed ) = 0;
  74. virtual ESteamAPICallFailure GetAPICallFailureReason( SteamAPICall_t hSteamAPICall ) = 0;
  75. virtual bool GetAPICallResult( SteamAPICall_t hSteamAPICall, void *pCallback, int cubCallback, int iCallbackExpected, bool *pbFailed ) = 0;
  76. // this needs to be called every frame to process matchmaking results
  77. // redundant if you're already calling SteamAPI_RunCallbacks()
  78. virtual void RunFrame() = 0;
  79. // returns the number of IPC calls made since the last time this function was called
  80. // Used for perf debugging so you can understand how many IPC calls your game makes per frame
  81. // Every IPC call is at minimum a thread context switch if not a process one so you want to rate
  82. // control how often you do them.
  83. virtual uint32 GetIPCCallCount() = 0;
  84. // API warning handling
  85. // 'int' is the severity; 0 for msg, 1 for warning
  86. // 'const char *' is the text of the message
  87. // callbacks will occur directly after the API function is called that generated the warning or message
  88. virtual void SetWarningMessageHook( SteamAPIWarningMessageHook_t pFunction ) = 0;
  89. // Returns true if the overlay is running & the user can access it. The overlay process could take a few seconds to
  90. // start & hook the game process, so this function will initially return false while the overlay is loading.
  91. virtual bool IsOverlayEnabled() = 0;
  92. // Normally this call is unneeded if your game has a constantly running frame loop that calls the
  93. // D3D Present API, or OGL SwapBuffers API every frame.
  94. //
  95. // However, if you have a game that only refreshes the screen on an event driven basis then that can break
  96. // the overlay, as it uses your Present/SwapBuffers calls to drive it's internal frame loop and it may also
  97. // need to Present() to the screen any time an even needing a notification happens or when the overlay is
  98. // brought up over the game by a user. You can use this API to ask the overlay if it currently need a present
  99. // in that case, and then you can check for this periodically (roughly 33hz is desirable) and make sure you
  100. // refresh the screen with Present or SwapBuffers to allow the overlay to do it's work.
  101. virtual bool BOverlayNeedsPresent() = 0;
  102. #ifndef _PS3
  103. // Asynchronous call to check if an executable file has been signed using the public key set on the signing tab
  104. // of the partner site, for example to refuse to load modified executable files.
  105. // The result is returned in CheckFileSignature_t.
  106. // k_ECheckFileSignatureNoSignaturesFoundForThisApp - This app has not been configured on the signing tab of the partner site to enable this function.
  107. // k_ECheckFileSignatureNoSignaturesFoundForThisFile - This file is not listed on the signing tab for the partner site.
  108. // k_ECheckFileSignatureFileNotFound - The file does not exist on disk.
  109. // k_ECheckFileSignatureInvalidSignature - The file exists, and the signing tab has been set for this file, but the file is either not signed or the signature does not match.
  110. // k_ECheckFileSignatureValidSignature - The file is signed and the signature is valid.
  111. virtual SteamAPICall_t CheckFileSignature( const char *szFileName ) = 0;
  112. #endif
  113. #ifdef _PS3
  114. virtual void PostPS3SysutilCallback( uint64_t status, uint64_t param, void* userdata ) = 0;
  115. virtual bool BIsReadyToShutdown() = 0;
  116. virtual bool BIsPSNOnline() = 0;
  117. // Call this with localized strings for the language the game is running in, otherwise default english
  118. // strings will be used by Steam.
  119. virtual void SetPSNGameBootInviteStrings( const char *pchSubject, const char *pchBody ) = 0;
  120. #endif
  121. // Activates the Big Picture text input dialog which only supports gamepad input
  122. virtual bool ShowGamepadTextInput( EGamepadTextInputMode eInputMode, EGamepadTextInputLineMode eLineInputMode, const char *pchDescription, uint32 unCharMax, const char *pchExistingText ) = 0;
  123. // Returns previously entered text & length
  124. virtual uint32 GetEnteredGamepadTextLength() = 0;
  125. virtual bool GetEnteredGamepadTextInput( char *pchText, uint32 cchText ) = 0;
  126. // returns the language the steam client is running in, you probably want ISteamApps::GetCurrentGameLanguage instead, this is for very special usage cases
  127. virtual const char *GetSteamUILanguage() = 0;
  128. // returns true if Steam itself is running in VR mode
  129. virtual bool IsSteamRunningInVR() = 0;
  130. // Sets the inset of the overlay notification from the corner specified by SetOverlayNotificationPosition.
  131. virtual void SetOverlayNotificationInset( int nHorizontalInset, int nVerticalInset ) = 0;
  132. };
  133. #define STEAMUTILS_INTERFACE_VERSION "SteamUtils007"
  134. // callbacks
  135. #if defined( VALVE_CALLBACK_PACK_SMALL )
  136. #pragma pack( push, 4 )
  137. #elif defined( VALVE_CALLBACK_PACK_LARGE )
  138. #pragma pack( push, 8 )
  139. #else
  140. #error isteamclient.h must be included
  141. #endif
  142. //-----------------------------------------------------------------------------
  143. // Purpose: The country of the user changed
  144. //-----------------------------------------------------------------------------
  145. struct IPCountry_t
  146. {
  147. enum { k_iCallback = k_iSteamUtilsCallbacks + 1 };
  148. };
  149. //-----------------------------------------------------------------------------
  150. // Purpose: Fired when running on a laptop and less than 10 minutes of battery is left, fires then every minute
  151. //-----------------------------------------------------------------------------
  152. struct LowBatteryPower_t
  153. {
  154. enum { k_iCallback = k_iSteamUtilsCallbacks + 2 };
  155. uint8 m_nMinutesBatteryLeft;
  156. };
  157. //-----------------------------------------------------------------------------
  158. // Purpose: called when a SteamAsyncCall_t has completed (or failed)
  159. //-----------------------------------------------------------------------------
  160. struct SteamAPICallCompleted_t
  161. {
  162. enum { k_iCallback = k_iSteamUtilsCallbacks + 3 };
  163. SteamAPICall_t m_hAsyncCall;
  164. };
  165. //-----------------------------------------------------------------------------
  166. // called when Steam wants to shutdown
  167. //-----------------------------------------------------------------------------
  168. struct SteamShutdown_t
  169. {
  170. enum { k_iCallback = k_iSteamUtilsCallbacks + 4 };
  171. };
  172. //-----------------------------------------------------------------------------
  173. // results for CheckFileSignature
  174. //-----------------------------------------------------------------------------
  175. enum ECheckFileSignature
  176. {
  177. k_ECheckFileSignatureInvalidSignature = 0,
  178. k_ECheckFileSignatureValidSignature = 1,
  179. k_ECheckFileSignatureFileNotFound = 2,
  180. k_ECheckFileSignatureNoSignaturesFoundForThisApp = 3,
  181. k_ECheckFileSignatureNoSignaturesFoundForThisFile = 4,
  182. };
  183. //-----------------------------------------------------------------------------
  184. // callback for CheckFileSignature
  185. //-----------------------------------------------------------------------------
  186. struct CheckFileSignature_t
  187. {
  188. enum { k_iCallback = k_iSteamUtilsCallbacks + 5 };
  189. ECheckFileSignature m_eCheckFileSignature;
  190. };
  191. #ifdef _PS3
  192. //-----------------------------------------------------------------------------
  193. // callback for NetCtlNetStartDialog finishing on PS3
  194. //-----------------------------------------------------------------------------
  195. struct NetStartDialogFinished_t
  196. {
  197. enum { k_iCallback = k_iSteamUtilsCallbacks + 6 };
  198. };
  199. //-----------------------------------------------------------------------------
  200. // callback for NetCtlNetStartDialog unloaded on PS3
  201. //-----------------------------------------------------------------------------
  202. struct NetStartDialogUnloaded_t
  203. {
  204. enum { k_iCallback = k_iSteamUtilsCallbacks + 7 };
  205. };
  206. //-----------------------------------------------------------------------------
  207. // callback for system menu closing on PS3 - should trigger resyncronizing friends list, etc.
  208. //-----------------------------------------------------------------------------
  209. struct PS3SystemMenuClosed_t
  210. {
  211. enum { k_iCallback = k_iSteamUtilsCallbacks + 8 };
  212. };
  213. //-----------------------------------------------------------------------------
  214. // callback for NP message being selected by user on PS3 - should trigger handling of message if it's a lobby invite, etc.
  215. //-----------------------------------------------------------------------------
  216. struct PS3NPMessageSelected_t
  217. {
  218. enum { k_iCallback = k_iSteamUtilsCallbacks + 9 };
  219. uint32 dataid;
  220. };
  221. //-----------------------------------------------------------------------------
  222. // callback for when the PS3 keyboard dialog closes
  223. //-----------------------------------------------------------------------------
  224. struct PS3KeyboardDialogFinished_t
  225. {
  226. enum { k_iCallback = k_iSteamUtilsCallbacks + 10 };
  227. };
  228. // k_iSteamUtilsCallbacks + 11 is taken
  229. //-----------------------------------------------------------------------------
  230. // callback for PSN status changing on PS3
  231. //-----------------------------------------------------------------------------
  232. struct PS3PSNStatusChange_t
  233. {
  234. enum { k_iCallback = k_iSteamUtilsCallbacks + 12 };
  235. bool m_bPSNOnline;
  236. };
  237. #endif
  238. // k_iSteamUtilsCallbacks + 13 is taken
  239. //-----------------------------------------------------------------------------
  240. // Big Picture gamepad text input has been closed
  241. //-----------------------------------------------------------------------------
  242. struct GamepadTextInputDismissed_t
  243. {
  244. enum { k_iCallback = k_iSteamUtilsCallbacks + 14 };
  245. bool m_bSubmitted; // true if user entered & accepted text (Call ISteamUtils::GetEnteredGamepadTextInput() for text), false if canceled input
  246. uint32 m_unSubmittedText;
  247. };
  248. // k_iSteamUtilsCallbacks + 15 is taken
  249. #pragma pack( pop )
  250. #endif // ISTEAMUTILS_H