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.

650 lines
24 KiB

  1. //====== Copyright 1996-2008, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef STEAM_API_H
  7. #define STEAM_API_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "isteamclient.h"
  12. #include "isteamuser.h"
  13. #include "isteamfriends.h"
  14. #include "isteamutils.h"
  15. #include "isteammatchmaking.h"
  16. #include "isteamuserstats.h"
  17. #include "isteamapps.h"
  18. #include "isteamnetworking.h"
  19. #include "isteamremotestorage.h"
  20. #include "isteamscreenshots.h"
  21. #include "isteammusic.h"
  22. #include "isteammusicremote.h"
  23. #include "isteamhttp.h"
  24. #include "isteamunifiedmessages.h"
  25. #include "isteamcontroller.h"
  26. #include "isteamugc.h"
  27. #include "isteamapplist.h"
  28. #include "isteamhtmlsurface.h"
  29. #include "isteaminventory.h"
  30. #include "isteamvideo.h"
  31. #if defined( _PS3 )
  32. #include "steamps3params.h"
  33. #endif
  34. // Steam API export macro
  35. #if defined( _WIN32 ) && !defined( _X360 )
  36. #if defined( STEAM_API_EXPORTS )
  37. #define S_API extern "C" __declspec( dllexport )
  38. #elif defined( STEAM_API_NODLL )
  39. #define S_API extern "C"
  40. #else
  41. #define S_API extern "C" __declspec( dllimport )
  42. #endif // STEAM_API_EXPORTS
  43. #elif defined( GNUC )
  44. #if defined( STEAM_API_EXPORTS )
  45. #define S_API extern "C" __attribute__ ((visibility("default")))
  46. #else
  47. #define S_API extern "C"
  48. #endif // STEAM_API_EXPORTS
  49. #else // !WIN32
  50. #if defined( STEAM_API_EXPORTS )
  51. #define S_API extern "C"
  52. #else
  53. #define S_API extern "C"
  54. #endif // STEAM_API_EXPORTS
  55. #endif
  56. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  57. // Steam API setup & shutdown
  58. //
  59. // These functions manage loading, initializing and shutdown of the steamclient.dll
  60. //
  61. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  62. // S_API void SteamAPI_Init(); (see below)
  63. S_API void S_CALLTYPE SteamAPI_Shutdown();
  64. // checks if a local Steam client is running
  65. S_API bool S_CALLTYPE SteamAPI_IsSteamRunning();
  66. // Detects if your executable was launched through the Steam client, and restarts your game through
  67. // the client if necessary. The Steam client will be started if it is not running.
  68. //
  69. // Returns: true if your executable was NOT launched through the Steam client. This function will
  70. // then start your application through the client. Your current process should exit.
  71. //
  72. // false if your executable was started through the Steam client or a steam_appid.txt file
  73. // is present in your game's directory (for development). Your current process should continue.
  74. //
  75. // NOTE: This function should be used only if you are using CEG or not using Steam's DRM. Once applied
  76. // to your executable, Steam's DRM will handle restarting through Steam if necessary.
  77. S_API bool S_CALLTYPE SteamAPI_RestartAppIfNecessary( uint32 unOwnAppID );
  78. // crash dump recording functions
  79. S_API void S_CALLTYPE SteamAPI_WriteMiniDump( uint32 uStructuredExceptionCode, void* pvExceptionInfo, uint32 uBuildID );
  80. S_API void S_CALLTYPE SteamAPI_SetMiniDumpComment( const char *pchMsg );
  81. // interface pointers, configured by SteamAPI_Init()
  82. S_API ISteamClient *S_CALLTYPE SteamClient();
  83. //
  84. // VERSION_SAFE_STEAM_API_INTERFACES is usually not necessary, but it provides safety against releasing
  85. // new steam_api.dll's without recompiling/rereleasing modules that use it.
  86. //
  87. // If you use VERSION_SAFE_STEAM_API_INTERFACES, then you should call SteamAPI_InitSafe(). Also, to get the
  88. // Steam interfaces, you must create and Init() a CSteamAPIContext (below) and use the interfaces in there.
  89. //
  90. // If you don't use VERSION_SAFE_STEAM_API_INTERFACES, then you can use SteamAPI_Init() and the SteamXXXX()
  91. // functions below to get at the Steam interfaces.
  92. //
  93. #ifdef VERSION_SAFE_STEAM_API_INTERFACES
  94. S_API bool S_CALLTYPE SteamAPI_InitSafe();
  95. #else
  96. #if defined(_PS3)
  97. S_API bool S_CALLTYPE SteamAPI_Init( SteamPS3Params_t *pParams );
  98. #else
  99. S_API bool S_CALLTYPE SteamAPI_Init();
  100. #endif
  101. S_API ISteamUser *S_CALLTYPE SteamUser();
  102. S_API ISteamFriends *S_CALLTYPE SteamFriends();
  103. S_API ISteamUtils *S_CALLTYPE SteamUtils();
  104. S_API ISteamMatchmaking *S_CALLTYPE SteamMatchmaking();
  105. S_API ISteamUserStats *S_CALLTYPE SteamUserStats();
  106. S_API ISteamApps *S_CALLTYPE SteamApps();
  107. S_API ISteamNetworking *S_CALLTYPE SteamNetworking();
  108. S_API ISteamMatchmakingServers *S_CALLTYPE SteamMatchmakingServers();
  109. S_API ISteamRemoteStorage *S_CALLTYPE SteamRemoteStorage();
  110. S_API ISteamScreenshots *S_CALLTYPE SteamScreenshots();
  111. S_API ISteamHTTP *S_CALLTYPE SteamHTTP();
  112. S_API ISteamUnifiedMessages *S_CALLTYPE SteamUnifiedMessages();
  113. S_API ISteamController *S_CALLTYPE SteamController();
  114. S_API ISteamUGC *S_CALLTYPE SteamUGC();
  115. S_API ISteamAppList *S_CALLTYPE SteamAppList();
  116. S_API ISteamMusic *S_CALLTYPE SteamMusic();
  117. S_API ISteamMusicRemote *S_CALLTYPE SteamMusicRemote();
  118. S_API ISteamHTMLSurface *S_CALLTYPE SteamHTMLSurface();
  119. S_API ISteamInventory *S_CALLTYPE SteamInventory();
  120. S_API ISteamVideo *S_CALLTYPE SteamVideo();
  121. #ifdef _PS3
  122. S_API ISteamPS3OverlayRender *S_CALLTYPE SteamPS3OverlayRender();
  123. #endif
  124. #endif // VERSION_SAFE_STEAM_API_INTERFACES
  125. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  126. // steam callback and call-result helpers
  127. //
  128. // The following macros and classes are used to register your application for
  129. // callbacks and call-results, which are delivered in a predictable manner.
  130. //
  131. // STEAM_CALLBACK macros are meant for use inside of a C++ class definition.
  132. // They map a Steam notification callback directly to a class member function
  133. // which is automatically prototyped as "void func( callback_type *pParam )".
  134. //
  135. // CCallResult is used with specific Steam APIs that return "result handles".
  136. // The handle can be passed to a CCallResult object's Set function, along with
  137. // an object pointer and member-function pointer. The member function will
  138. // be executed once the results of the Steam API call are available.
  139. //
  140. // CCallback and CCallbackManual classes can be used instead of STEAM_CALLBACK
  141. // macros if you require finer control over registration and unregistration.
  142. //
  143. // Callbacks and call-results are queued automatically and are only
  144. // delivered/executed when your application calls SteamAPI_RunCallbacks().
  145. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  146. S_API void S_CALLTYPE SteamAPI_RunCallbacks();
  147. // Declares a callback member function plus a helper member variable which
  148. // registers the callback on object creation and unregisters on destruction.
  149. // The optional fourth 'var' param exists only for backwards-compatibility
  150. // and can be ignored.
  151. #define STEAM_CALLBACK( thisclass, func, .../*callback_type, [deprecated] var*/ ) \
  152. _STEAM_CALLBACK_SELECT( ( __VA_ARGS__, 4, 3 ), ( /**/, thisclass, func, __VA_ARGS__ ) )
  153. // Declares a callback function and a named CCallbackManual variable which
  154. // has Register and Unregister functions instead of automatic registration.
  155. #define STEAM_CALLBACK_MANUAL( thisclass, func, callback_type, var ) \
  156. CCallbackManual< thisclass, callback_type > var; void func( callback_type *pParam )
  157. // Internal functions used by the utility CCallback objects to receive callbacks
  158. S_API void S_CALLTYPE SteamAPI_RegisterCallback( class CCallbackBase *pCallback, int iCallback );
  159. S_API void S_CALLTYPE SteamAPI_UnregisterCallback( class CCallbackBase *pCallback );
  160. // Internal functions used by the utility CCallResult objects to receive async call results
  161. S_API void S_CALLTYPE SteamAPI_RegisterCallResult( class CCallbackBase *pCallback, SteamAPICall_t hAPICall );
  162. S_API void S_CALLTYPE SteamAPI_UnregisterCallResult( class CCallbackBase *pCallback, SteamAPICall_t hAPICall );
  163. //-----------------------------------------------------------------------------
  164. // Purpose: base for callbacks and call results - internal implementation detail
  165. //-----------------------------------------------------------------------------
  166. class CCallbackBase
  167. {
  168. public:
  169. CCallbackBase() { m_nCallbackFlags = 0; m_iCallback = 0; }
  170. // don't add a virtual destructor because we export this binary interface across dll's
  171. virtual void Run( void *pvParam ) = 0;
  172. virtual void Run( void *pvParam, bool bIOFailure, SteamAPICall_t hSteamAPICall ) = 0;
  173. int GetICallback() { return m_iCallback; }
  174. virtual int GetCallbackSizeBytes() = 0;
  175. protected:
  176. enum { k_ECallbackFlagsRegistered = 0x01, k_ECallbackFlagsGameServer = 0x02 };
  177. uint8 m_nCallbackFlags;
  178. int m_iCallback;
  179. friend class CCallbackMgr;
  180. private:
  181. CCallbackBase( const CCallbackBase& );
  182. CCallbackBase& operator=( const CCallbackBase& );
  183. };
  184. //-----------------------------------------------------------------------------
  185. // Purpose: templated base for callbacks - internal implementation detail
  186. //-----------------------------------------------------------------------------
  187. template< int sizeof_P >
  188. class CCallbackImpl : protected CCallbackBase
  189. {
  190. public:
  191. ~CCallbackImpl() { if ( m_nCallbackFlags & k_ECallbackFlagsRegistered ) SteamAPI_UnregisterCallback( this ); }
  192. void SetGameserverFlag() { m_nCallbackFlags |= k_ECallbackFlagsGameServer; }
  193. protected:
  194. virtual void Run( void *pvParam ) = 0;
  195. virtual void Run( void *pvParam, bool /*bIOFailure*/, SteamAPICall_t /*hSteamAPICall*/ ) { Run( pvParam ); }
  196. virtual int GetCallbackSizeBytes() { return sizeof_P; }
  197. };
  198. //-----------------------------------------------------------------------------
  199. // Purpose: maps a steam async call result to a class member function
  200. // template params: T = local class, P = parameter struct
  201. //-----------------------------------------------------------------------------
  202. template< class T, class P >
  203. class CCallResult : private CCallbackBase
  204. {
  205. public:
  206. typedef void (T::*func_t)( P*, bool );
  207. CCallResult()
  208. {
  209. m_hAPICall = k_uAPICallInvalid;
  210. m_pObj = NULL;
  211. m_Func = NULL;
  212. m_iCallback = P::k_iCallback;
  213. }
  214. void Set( SteamAPICall_t hAPICall, T *p, func_t func )
  215. {
  216. if ( m_hAPICall )
  217. SteamAPI_UnregisterCallResult( this, m_hAPICall );
  218. m_hAPICall = hAPICall;
  219. m_pObj = p;
  220. m_Func = func;
  221. if ( hAPICall )
  222. SteamAPI_RegisterCallResult( this, hAPICall );
  223. }
  224. bool IsActive() const
  225. {
  226. return ( m_hAPICall != k_uAPICallInvalid );
  227. }
  228. void Cancel()
  229. {
  230. if ( m_hAPICall != k_uAPICallInvalid )
  231. {
  232. SteamAPI_UnregisterCallResult( this, m_hAPICall );
  233. m_hAPICall = k_uAPICallInvalid;
  234. }
  235. }
  236. ~CCallResult()
  237. {
  238. Cancel();
  239. }
  240. void SetGameserverFlag() { m_nCallbackFlags |= k_ECallbackFlagsGameServer; }
  241. private:
  242. virtual void Run( void *pvParam )
  243. {
  244. m_hAPICall = k_uAPICallInvalid; // caller unregisters for us
  245. (m_pObj->*m_Func)( (P *)pvParam, false );
  246. }
  247. virtual void Run( void *pvParam, bool bIOFailure, SteamAPICall_t hSteamAPICall )
  248. {
  249. if ( hSteamAPICall == m_hAPICall )
  250. {
  251. m_hAPICall = k_uAPICallInvalid; // caller unregisters for us
  252. (m_pObj->*m_Func)( (P *)pvParam, bIOFailure );
  253. }
  254. }
  255. virtual int GetCallbackSizeBytes()
  256. {
  257. return sizeof( P );
  258. }
  259. SteamAPICall_t m_hAPICall;
  260. T *m_pObj;
  261. func_t m_Func;
  262. };
  263. //-----------------------------------------------------------------------------
  264. // Purpose: maps a steam callback to a class member function
  265. // template params: T = local class, P = parameter struct,
  266. // bGameserver = listen for gameserver callbacks instead of client callbacks
  267. //-----------------------------------------------------------------------------
  268. template< class T, class P, bool bGameserver = false >
  269. class CCallback : public CCallbackImpl< sizeof( P ) >
  270. {
  271. public:
  272. typedef void (T::*func_t)(P*);
  273. // NOTE: If you can't provide the correct parameters at construction time, you should
  274. // use the CCallbackManual callback object (STEAM_CALLBACK_MANUAL macro) instead.
  275. CCallback( T *pObj, func_t func ) : m_pObj( NULL ), m_Func( NULL )
  276. {
  277. if ( bGameserver )
  278. {
  279. this->SetGameserverFlag();
  280. }
  281. Register( pObj, func );
  282. }
  283. // manual registration of the callback
  284. void Register( T *pObj, func_t func )
  285. {
  286. if ( !pObj || !func )
  287. return;
  288. if ( this->m_nCallbackFlags & CCallbackBase::k_ECallbackFlagsRegistered )
  289. Unregister();
  290. m_pObj = pObj;
  291. m_Func = func;
  292. // SteamAPI_RegisterCallback sets k_ECallbackFlagsRegistered
  293. SteamAPI_RegisterCallback( this, P::k_iCallback );
  294. }
  295. void Unregister()
  296. {
  297. // SteamAPI_UnregisterCallback removes k_ECallbackFlagsRegistered
  298. SteamAPI_UnregisterCallback( this );
  299. }
  300. protected:
  301. virtual void Run( void *pvParam )
  302. {
  303. (m_pObj->*m_Func)( (P *)pvParam );
  304. }
  305. T *m_pObj;
  306. func_t m_Func;
  307. };
  308. //-----------------------------------------------------------------------------
  309. // Purpose: subclass of CCallback which allows default-construction in
  310. // an unregistered state; you must call Register manually
  311. //-----------------------------------------------------------------------------
  312. template< class T, class P, bool bGameServer = false >
  313. class CCallbackManual : public CCallback< T, P, bGameServer >
  314. {
  315. public:
  316. CCallbackManual() : CCallback< T, P, bGameServer >( NULL, NULL ) {}
  317. // Inherits public Register and Unregister functions from base class
  318. };
  319. //-----------------------------------------------------------------------------
  320. // The following macros are implementation details, not intended for public use
  321. //-----------------------------------------------------------------------------
  322. #define _STEAM_CALLBACK_AUTO_HOOK( thisclass, func, param )
  323. #define _STEAM_CALLBACK_HELPER( _1, _2, SELECTED, ... ) _STEAM_CALLBACK_##SELECTED
  324. #define _STEAM_CALLBACK_SELECT( X, Y ) _STEAM_CALLBACK_HELPER X Y
  325. #define _STEAM_CALLBACK_3( extra_code, thisclass, func, param ) \
  326. struct CCallbackInternal_ ## func : private CCallbackImpl< sizeof( param ) > { \
  327. CCallbackInternal_ ## func () { extra_code SteamAPI_RegisterCallback( this, param::k_iCallback ); } \
  328. CCallbackInternal_ ## func ( const CCallbackInternal_ ## func & ) { extra_code SteamAPI_RegisterCallback( this, param::k_iCallback ); } \
  329. CCallbackInternal_ ## func & operator=( const CCallbackInternal_ ## func & ) { return *this; } \
  330. private: virtual void Run( void *pvParam ) { _STEAM_CALLBACK_AUTO_HOOK( thisclass, func, param ) \
  331. thisclass *pOuter = reinterpret_cast<thisclass*>( reinterpret_cast<char*>(this) - offsetof( thisclass, m_steamcallback_ ## func ) ); \
  332. pOuter->func( reinterpret_cast<param*>( pvParam ) ); \
  333. } \
  334. } m_steamcallback_ ## func ; void func( param *pParam )
  335. #define _STEAM_CALLBACK_4( _, thisclass, func, param, var ) \
  336. CCallback< thisclass, param > var; void func( param *pParam )
  337. #ifdef _WIN32
  338. // disable this warning; this pattern need for steam callback registration
  339. #pragma warning( disable: 4355 ) // 'this' : used in base member initializer list
  340. #endif
  341. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  342. // steamclient.dll private wrapper functions
  343. //
  344. // The following functions are part of abstracting API access to the steamclient.dll, but should only be used in very specific cases
  345. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  346. // pumps out all the steam messages, calling the register callback
  347. S_API void Steam_RunCallbacks( HSteamPipe hSteamPipe, bool bGameServerCallbacks );
  348. // register the callback funcs to use to interact with the steam dll
  349. S_API void Steam_RegisterInterfaceFuncs( void *hModule );
  350. // returns the HSteamUser of the last user to dispatch a callback
  351. S_API HSteamUser Steam_GetHSteamUserCurrent();
  352. // returns the filename path of the current running Steam process, used if you need to load an explicit steam dll by name
  353. S_API const char *SteamAPI_GetSteamInstallPath();
  354. // returns the pipe we are communicating to Steam with
  355. S_API HSteamPipe SteamAPI_GetHSteamPipe();
  356. // sets whether or not Steam_RunCallbacks() should do a try {} catch (...) {} around calls to issuing callbacks
  357. S_API void SteamAPI_SetTryCatchCallbacks( bool bTryCatchCallbacks );
  358. // backwards compat export, passes through to SteamAPI_ variants
  359. S_API HSteamPipe GetHSteamPipe();
  360. S_API HSteamUser GetHSteamUser();
  361. #ifdef VERSION_SAFE_STEAM_API_INTERFACES
  362. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  363. // VERSION_SAFE_STEAM_API_INTERFACES uses CSteamAPIContext to provide interfaces to each module in a way that
  364. // lets them each specify the interface versions they are compiled with.
  365. //
  366. // It's important that these stay inlined in the header so the calling module specifies the interface versions
  367. // for whatever Steam API version it has.
  368. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  369. S_API HSteamUser SteamAPI_GetHSteamUser();
  370. class CSteamAPIContext
  371. {
  372. public:
  373. CSteamAPIContext();
  374. void Clear();
  375. bool Init();
  376. ISteamUser* SteamUser() { return m_pSteamUser; }
  377. ISteamFriends* SteamFriends() { return m_pSteamFriends; }
  378. ISteamUtils* SteamUtils() { return m_pSteamUtils; }
  379. ISteamMatchmaking* SteamMatchmaking() { return m_pSteamMatchmaking; }
  380. ISteamUserStats* SteamUserStats() { return m_pSteamUserStats; }
  381. ISteamApps* SteamApps() { return m_pSteamApps; }
  382. ISteamMatchmakingServers* SteamMatchmakingServers() { return m_pSteamMatchmakingServers; }
  383. ISteamNetworking* SteamNetworking() { return m_pSteamNetworking; }
  384. ISteamRemoteStorage* SteamRemoteStorage() { return m_pSteamRemoteStorage; }
  385. ISteamScreenshots* SteamScreenshots() { return m_pSteamScreenshots; }
  386. ISteamHTTP* SteamHTTP() { return m_pSteamHTTP; }
  387. ISteamUnifiedMessages* SteamUnifiedMessages() { return m_pSteamUnifiedMessages; }
  388. ISteamController* SteamController() { return m_pController; }
  389. ISteamUGC* SteamUGC() { return m_pSteamUGC; }
  390. ISteamAppList* SteamAppList() { return m_pSteamAppList; }
  391. ISteamMusic* SteamMusic() { return m_pSteamMusic; }
  392. ISteamMusicRemote* SteamMusicRemote() { return m_pSteamMusicRemote; }
  393. ISteamHTMLSurface* SteamHTMLSurface() { return m_pSteamHTMLSurface; }
  394. ISteamInventory* SteamInventory() { return m_pSteamInventory; }
  395. ISteamVideo* SteamVideo() { return m_pSteamVideo; }
  396. #ifdef _PS3
  397. ISteamPS3OverlayRender* SteamPS3OverlayRender() { return m_pSteamPS3OverlayRender; }
  398. #endif
  399. private:
  400. ISteamUser *m_pSteamUser;
  401. ISteamFriends *m_pSteamFriends;
  402. ISteamUtils *m_pSteamUtils;
  403. ISteamMatchmaking *m_pSteamMatchmaking;
  404. ISteamUserStats *m_pSteamUserStats;
  405. ISteamApps *m_pSteamApps;
  406. ISteamMatchmakingServers *m_pSteamMatchmakingServers;
  407. ISteamNetworking *m_pSteamNetworking;
  408. ISteamRemoteStorage *m_pSteamRemoteStorage;
  409. ISteamScreenshots *m_pSteamScreenshots;
  410. ISteamHTTP *m_pSteamHTTP;
  411. ISteamUnifiedMessages*m_pSteamUnifiedMessages;
  412. ISteamController *m_pController;
  413. ISteamUGC *m_pSteamUGC;
  414. ISteamAppList *m_pSteamAppList;
  415. ISteamMusic *m_pSteamMusic;
  416. ISteamMusicRemote *m_pSteamMusicRemote;
  417. ISteamHTMLSurface *m_pSteamHTMLSurface;
  418. ISteamInventory *m_pSteamInventory;
  419. ISteamVideo *m_pSteamVideo;
  420. #ifdef _PS3
  421. ISteamPS3OverlayRender *m_pSteamPS3OverlayRender;
  422. #endif
  423. };
  424. inline CSteamAPIContext::CSteamAPIContext()
  425. {
  426. Clear();
  427. }
  428. inline void CSteamAPIContext::Clear()
  429. {
  430. m_pSteamUser = NULL;
  431. m_pSteamFriends = NULL;
  432. m_pSteamUtils = NULL;
  433. m_pSteamMatchmaking = NULL;
  434. m_pSteamUserStats = NULL;
  435. m_pSteamApps = NULL;
  436. m_pSteamMatchmakingServers = NULL;
  437. m_pSteamNetworking = NULL;
  438. m_pSteamRemoteStorage = NULL;
  439. m_pSteamHTTP = NULL;
  440. m_pSteamScreenshots = NULL;
  441. m_pSteamMusic = NULL;
  442. m_pSteamUnifiedMessages = NULL;
  443. m_pController = NULL;
  444. m_pSteamUGC = NULL;
  445. m_pSteamAppList = NULL;
  446. m_pSteamMusic = NULL;
  447. m_pSteamMusicRemote= NULL;
  448. m_pSteamHTMLSurface = NULL;
  449. m_pSteamInventory = NULL;
  450. #ifdef _PS3
  451. m_pSteamPS3OverlayRender = NULL;
  452. #endif
  453. }
  454. // This function must be inlined so the module using steam_api.dll gets the version names they want.
  455. inline bool CSteamAPIContext::Init()
  456. {
  457. if ( !SteamClient() )
  458. return false;
  459. HSteamUser hSteamUser = SteamAPI_GetHSteamUser();
  460. HSteamPipe hSteamPipe = SteamAPI_GetHSteamPipe();
  461. m_pSteamUser = SteamClient()->GetISteamUser( hSteamUser, hSteamPipe, STEAMUSER_INTERFACE_VERSION );
  462. if ( !m_pSteamUser )
  463. return false;
  464. m_pSteamFriends = SteamClient()->GetISteamFriends( hSteamUser, hSteamPipe, STEAMFRIENDS_INTERFACE_VERSION );
  465. if ( !m_pSteamFriends )
  466. return false;
  467. m_pSteamUtils = SteamClient()->GetISteamUtils( hSteamPipe, STEAMUTILS_INTERFACE_VERSION );
  468. if ( !m_pSteamUtils )
  469. return false;
  470. m_pSteamMatchmaking = SteamClient()->GetISteamMatchmaking( hSteamUser, hSteamPipe, STEAMMATCHMAKING_INTERFACE_VERSION );
  471. if ( !m_pSteamMatchmaking )
  472. return false;
  473. m_pSteamMatchmakingServers = SteamClient()->GetISteamMatchmakingServers( hSteamUser, hSteamPipe, STEAMMATCHMAKINGSERVERS_INTERFACE_VERSION );
  474. if ( !m_pSteamMatchmakingServers )
  475. return false;
  476. m_pSteamUserStats = SteamClient()->GetISteamUserStats( hSteamUser, hSteamPipe, STEAMUSERSTATS_INTERFACE_VERSION );
  477. if ( !m_pSteamUserStats )
  478. return false;
  479. m_pSteamApps = SteamClient()->GetISteamApps( hSteamUser, hSteamPipe, STEAMAPPS_INTERFACE_VERSION );
  480. if ( !m_pSteamApps )
  481. return false;
  482. m_pSteamNetworking = SteamClient()->GetISteamNetworking( hSteamUser, hSteamPipe, STEAMNETWORKING_INTERFACE_VERSION );
  483. if ( !m_pSteamNetworking )
  484. return false;
  485. m_pSteamRemoteStorage = SteamClient()->GetISteamRemoteStorage( hSteamUser, hSteamPipe, STEAMREMOTESTORAGE_INTERFACE_VERSION );
  486. if ( !m_pSteamRemoteStorage )
  487. return false;
  488. m_pSteamScreenshots = SteamClient()->GetISteamScreenshots( hSteamUser, hSteamPipe, STEAMSCREENSHOTS_INTERFACE_VERSION );
  489. if ( !m_pSteamScreenshots )
  490. return false;
  491. m_pSteamHTTP = SteamClient()->GetISteamHTTP( hSteamUser, hSteamPipe, STEAMHTTP_INTERFACE_VERSION );
  492. if ( !m_pSteamHTTP )
  493. return false;
  494. m_pSteamUnifiedMessages = SteamClient()->GetISteamUnifiedMessages( hSteamUser, hSteamPipe, STEAMUNIFIEDMESSAGES_INTERFACE_VERSION );
  495. if ( !m_pSteamUnifiedMessages )
  496. return false;
  497. m_pController = SteamClient()->GetISteamController( hSteamUser, hSteamPipe, STEAMCONTROLLER_INTERFACE_VERSION );
  498. if ( !m_pController )
  499. return false;
  500. m_pSteamUGC = SteamClient()->GetISteamUGC( hSteamUser, hSteamPipe, STEAMUGC_INTERFACE_VERSION );
  501. if ( !m_pSteamUGC )
  502. return false;
  503. m_pSteamAppList = SteamClient()->GetISteamAppList( hSteamUser, hSteamPipe, STEAMAPPLIST_INTERFACE_VERSION );
  504. if ( !m_pSteamAppList )
  505. return false;
  506. m_pSteamMusic = SteamClient()->GetISteamMusic( hSteamUser, hSteamPipe, STEAMMUSIC_INTERFACE_VERSION );
  507. if ( !m_pSteamMusic )
  508. {
  509. return false;
  510. }
  511. m_pSteamMusicRemote = SteamClient()->GetISteamMusicRemote( hSteamUser, hSteamPipe, STEAMMUSICREMOTE_INTERFACE_VERSION );
  512. if ( !m_pSteamMusicRemote )
  513. {
  514. return false;
  515. }
  516. m_pSteamHTMLSurface = SteamClient()->GetISteamHTMLSurface( hSteamUser, hSteamPipe, STEAMHTMLSURFACE_INTERFACE_VERSION );
  517. if ( !m_pSteamHTMLSurface )
  518. {
  519. return false;
  520. }
  521. m_pSteamInventory = SteamClient()->GetISteamInventory( hSteamUser, hSteamPipe, STEAMINVENTORY_INTERFACE_VERSION );
  522. if ( !m_pSteamInventory )
  523. {
  524. return false;
  525. }
  526. m_pSteamVideo = SteamClient()->GetISteamVideo( hSteamUser, hSteamPipe, STEAMVIDEO_INTERFACE_VERSION );
  527. if ( !m_pSteamVideo )
  528. {
  529. return false;
  530. }
  531. #ifdef _PS3
  532. m_pSteamPS3OverlayRender = SteamClient()->GetISteamPS3OverlayRender();
  533. #endif
  534. return true;
  535. }
  536. #endif // VERSION_SAFE_STEAM_API_INTERFACES
  537. #if defined(USE_BREAKPAD_HANDLER) || defined(STEAM_API_EXPORTS)
  538. // this should be called before the game initialized the steam APIs
  539. // pchDate should be of the format "Mmm dd yyyy" (such as from the __DATE__ macro )
  540. // pchTime should be of the format "hh:mm:ss" (such as from the __TIME__ macro )
  541. // bFullMemoryDumps (Win32 only) -- writes out a uuid-full.dmp in the client/dumps folder
  542. // pvContext-- can be NULL, will be the void * context passed into m_pfnPreMinidumpCallback
  543. // PFNPreMinidumpCallback m_pfnPreMinidumpCallback -- optional callback which occurs just before a .dmp file is written during a crash. Applications can hook this to allow adding additional information into the .dmp comment stream.
  544. S_API void S_CALLTYPE SteamAPI_UseBreakpadCrashHandler( char const *pchVersion, char const *pchDate, char const *pchTime, bool bFullMemoryDumps, void *pvContext, PFNPreMinidumpCallback m_pfnPreMinidumpCallback );
  545. S_API void S_CALLTYPE SteamAPI_SetBreakpadAppID( uint32 unAppID );
  546. #endif
  547. #endif // STEAM_API_H