Counter Strike : Global Offensive Source Code
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.

327 lines
13 KiB

  1. //====== Copyright 1996-2015, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: Internal private Steamworks API declarations and definitions
  4. //
  5. //=============================================================================
  6. #ifndef STEAM_API_INTERNAL_H
  7. #define STEAM_API_INTERNAL_H
  8. S_API HSteamUser SteamAPI_GetHSteamUser();
  9. S_API bool S_CALLTYPE SteamInternal_Init();
  10. S_API void * S_CALLTYPE SteamInternal_CreateInterface( const char *ver );
  11. S_API void * S_CALLTYPE SteamGameServerInternal_CreateInterface( const char *ver );
  12. #if !defined( STEAM_API_EXPORTS )
  13. #if !defined( VERSION_SAFE_STEAM_API_INTERFACES )
  14. inline CSteamAPIContext& SteamInternal_ModuleContext()
  15. {
  16. // NOTE: declaring "static CSteamAPIConext" creates a large function
  17. // which queries the initialization status of the object. We know that
  18. // it is pointer-aligned and fully memset with zeros, so just alias a
  19. // static buffer of the appropriate size and call it a CSteamAPIContext.
  20. static void* ctx[ sizeof(CSteamAPIContext)/sizeof(void*) ];
  21. return *(CSteamAPIContext*)ctx;
  22. }
  23. #define _STEAMINTERNAL_ACCESSOR_BODY( AccessFunc ) \
  24. if ( !SteamAPI_GetHSteamPipe() ) return 0; \
  25. CSteamAPIContext &ctx = SteamInternal_ModuleContext(); \
  26. if ( !ctx.AccessFunc() ) ctx.Init(); \
  27. return ctx.AccessFunc();
  28. inline ISteamClient *SteamClient() { _STEAMINTERNAL_ACCESSOR_BODY( SteamClient ) }
  29. inline ISteamUser *SteamUser() { _STEAMINTERNAL_ACCESSOR_BODY( SteamUser ) }
  30. inline ISteamFriends *SteamFriends() { _STEAMINTERNAL_ACCESSOR_BODY( SteamFriends ) }
  31. inline ISteamUtils *SteamUtils() { _STEAMINTERNAL_ACCESSOR_BODY( SteamUtils ) }
  32. inline ISteamMatchmaking *SteamMatchmaking() { _STEAMINTERNAL_ACCESSOR_BODY( SteamMatchmaking ) }
  33. inline ISteamUserStats *SteamUserStats() { _STEAMINTERNAL_ACCESSOR_BODY( SteamUserStats ) }
  34. inline ISteamApps *SteamApps() { _STEAMINTERNAL_ACCESSOR_BODY( SteamApps ) }
  35. inline ISteamMatchmakingServers *SteamMatchmakingServers() { _STEAMINTERNAL_ACCESSOR_BODY( SteamMatchmakingServers ) }
  36. inline ISteamNetworking *SteamNetworking() { _STEAMINTERNAL_ACCESSOR_BODY( SteamNetworking ) }
  37. inline ISteamRemoteStorage *SteamRemoteStorage() { _STEAMINTERNAL_ACCESSOR_BODY( SteamRemoteStorage ) }
  38. inline ISteamScreenshots *SteamScreenshots() { _STEAMINTERNAL_ACCESSOR_BODY( SteamScreenshots ) }
  39. inline ISteamHTTP *SteamHTTP() { _STEAMINTERNAL_ACCESSOR_BODY( SteamHTTP ) }
  40. inline ISteamUnifiedMessages *SteamUnifiedMessages() { _STEAMINTERNAL_ACCESSOR_BODY( SteamUnifiedMessages ) }
  41. inline ISteamController *SteamController() { _STEAMINTERNAL_ACCESSOR_BODY( SteamController ) }
  42. inline ISteamUGC *SteamUGC() { _STEAMINTERNAL_ACCESSOR_BODY( SteamUGC ) }
  43. inline ISteamAppList *SteamAppList() { _STEAMINTERNAL_ACCESSOR_BODY( SteamAppList ) }
  44. inline ISteamMusic *SteamMusic() { _STEAMINTERNAL_ACCESSOR_BODY( SteamMusic ) }
  45. inline ISteamMusicRemote *SteamMusicRemote() { _STEAMINTERNAL_ACCESSOR_BODY( SteamMusicRemote ) }
  46. inline ISteamHTMLSurface *SteamHTMLSurface() { _STEAMINTERNAL_ACCESSOR_BODY( SteamHTMLSurface ) }
  47. inline ISteamInventory *SteamInventory() { _STEAMINTERNAL_ACCESSOR_BODY( SteamInventory ) }
  48. inline ISteamVideo *SteamVideo() { _STEAMINTERNAL_ACCESSOR_BODY( SteamVideo ) }
  49. #undef _STEAMINTERNAL_ACCESSOR_BODY
  50. #endif // !defined( VERSION_SAFE_STEAM_API_INTERFACES )
  51. #endif // !defined( STEAM_API_EXPORTS )
  52. inline void CSteamAPIContext::Clear()
  53. {
  54. m_pSteamClient = NULL;
  55. m_pSteamUser = NULL;
  56. m_pSteamFriends = NULL;
  57. m_pSteamUtils = NULL;
  58. m_pSteamMatchmaking = NULL;
  59. m_pSteamUserStats = NULL;
  60. m_pSteamApps = NULL;
  61. m_pSteamMatchmakingServers = NULL;
  62. m_pSteamNetworking = NULL;
  63. m_pSteamRemoteStorage = NULL;
  64. m_pSteamHTTP = NULL;
  65. m_pSteamScreenshots = NULL;
  66. m_pSteamMusic = NULL;
  67. m_pSteamUnifiedMessages = NULL;
  68. m_pController = NULL;
  69. m_pSteamUGC = NULL;
  70. m_pSteamAppList = NULL;
  71. m_pSteamMusic = NULL;
  72. m_pSteamMusicRemote = NULL;
  73. m_pSteamHTMLSurface = NULL;
  74. m_pSteamInventory = NULL;
  75. }
  76. // This function must be declared inline in the header so the module using steam_api.dll gets the version names they want.
  77. inline bool CSteamAPIContext::Init()
  78. {
  79. HSteamUser hSteamUser = SteamAPI_GetHSteamUser();
  80. HSteamPipe hSteamPipe = SteamAPI_GetHSteamPipe();
  81. if ( !hSteamPipe )
  82. return false;
  83. m_pSteamClient = (ISteamClient*) SteamInternal_CreateInterface( STEAMCLIENT_INTERFACE_VERSION );
  84. if ( !m_pSteamClient )
  85. return false;
  86. m_pSteamUser = m_pSteamClient->GetISteamUser( hSteamUser, hSteamPipe, STEAMUSER_INTERFACE_VERSION );
  87. if ( !m_pSteamUser )
  88. return false;
  89. m_pSteamFriends = m_pSteamClient->GetISteamFriends( hSteamUser, hSteamPipe, STEAMFRIENDS_INTERFACE_VERSION );
  90. if ( !m_pSteamFriends )
  91. return false;
  92. m_pSteamUtils = m_pSteamClient->GetISteamUtils( hSteamPipe, STEAMUTILS_INTERFACE_VERSION );
  93. if ( !m_pSteamUtils )
  94. return false;
  95. m_pSteamMatchmaking = m_pSteamClient->GetISteamMatchmaking( hSteamUser, hSteamPipe, STEAMMATCHMAKING_INTERFACE_VERSION );
  96. if ( !m_pSteamMatchmaking )
  97. return false;
  98. m_pSteamMatchmakingServers = m_pSteamClient->GetISteamMatchmakingServers( hSteamUser, hSteamPipe, STEAMMATCHMAKINGSERVERS_INTERFACE_VERSION );
  99. if ( !m_pSteamMatchmakingServers )
  100. return false;
  101. m_pSteamUserStats = m_pSteamClient->GetISteamUserStats( hSteamUser, hSteamPipe, STEAMUSERSTATS_INTERFACE_VERSION );
  102. if ( !m_pSteamUserStats )
  103. return false;
  104. m_pSteamApps = m_pSteamClient->GetISteamApps( hSteamUser, hSteamPipe, STEAMAPPS_INTERFACE_VERSION );
  105. if ( !m_pSteamApps )
  106. return false;
  107. m_pSteamNetworking = m_pSteamClient->GetISteamNetworking( hSteamUser, hSteamPipe, STEAMNETWORKING_INTERFACE_VERSION );
  108. if ( !m_pSteamNetworking )
  109. return false;
  110. m_pSteamRemoteStorage = m_pSteamClient->GetISteamRemoteStorage( hSteamUser, hSteamPipe, STEAMREMOTESTORAGE_INTERFACE_VERSION );
  111. if ( !m_pSteamRemoteStorage )
  112. return false;
  113. m_pSteamScreenshots = m_pSteamClient->GetISteamScreenshots( hSteamUser, hSteamPipe, STEAMSCREENSHOTS_INTERFACE_VERSION );
  114. if ( !m_pSteamScreenshots )
  115. return false;
  116. m_pSteamHTTP = m_pSteamClient->GetISteamHTTP( hSteamUser, hSteamPipe, STEAMHTTP_INTERFACE_VERSION );
  117. if ( !m_pSteamHTTP )
  118. return false;
  119. m_pSteamUnifiedMessages = m_pSteamClient->GetISteamUnifiedMessages( hSteamUser, hSteamPipe, STEAMUNIFIEDMESSAGES_INTERFACE_VERSION );
  120. if ( !m_pSteamUnifiedMessages )
  121. return false;
  122. m_pController = m_pSteamClient->GetISteamController( hSteamUser, hSteamPipe, STEAMCONTROLLER_INTERFACE_VERSION );
  123. if ( !m_pController )
  124. return false;
  125. m_pSteamUGC = m_pSteamClient->GetISteamUGC( hSteamUser, hSteamPipe, STEAMUGC_INTERFACE_VERSION );
  126. if ( !m_pSteamUGC )
  127. return false;
  128. m_pSteamAppList = m_pSteamClient->GetISteamAppList( hSteamUser, hSteamPipe, STEAMAPPLIST_INTERFACE_VERSION );
  129. if ( !m_pSteamAppList )
  130. return false;
  131. m_pSteamMusic = m_pSteamClient->GetISteamMusic( hSteamUser, hSteamPipe, STEAMMUSIC_INTERFACE_VERSION );
  132. if ( !m_pSteamMusic )
  133. return false;
  134. m_pSteamMusicRemote = m_pSteamClient->GetISteamMusicRemote( hSteamUser, hSteamPipe, STEAMMUSICREMOTE_INTERFACE_VERSION );
  135. if ( !m_pSteamMusicRemote )
  136. return false;
  137. m_pSteamHTMLSurface = m_pSteamClient->GetISteamHTMLSurface( hSteamUser, hSteamPipe, STEAMHTMLSURFACE_INTERFACE_VERSION );
  138. if ( !m_pSteamHTMLSurface )
  139. return false;
  140. m_pSteamInventory = m_pSteamClient->GetISteamInventory( hSteamUser, hSteamPipe, STEAMINVENTORY_INTERFACE_VERSION );
  141. if ( !m_pSteamInventory )
  142. return false;
  143. m_pSteamVideo = m_pSteamClient->GetISteamVideo( hSteamUser, hSteamPipe, STEAMVIDEO_INTERFACE_VERSION );
  144. if ( !m_pSteamVideo )
  145. return false;
  146. return true;
  147. }
  148. //-----------------------------------------------------------------------------
  149. // The following macros are implementation details, not intended for public use
  150. //-----------------------------------------------------------------------------
  151. #define _STEAM_CALLBACK_AUTO_HOOK( thisclass, func, param )
  152. #define _STEAM_CALLBACK_HELPER( _1, _2, SELECTED, ... ) _STEAM_CALLBACK_##SELECTED
  153. #define _STEAM_CALLBACK_SELECT( X, Y ) _STEAM_CALLBACK_HELPER X Y
  154. #define _STEAM_CALLBACK_3( extra_code, thisclass, func, param ) \
  155. struct CCallbackInternal_ ## func : private CCallbackImpl< sizeof( param ) > { \
  156. CCallbackInternal_ ## func () { extra_code SteamAPI_RegisterCallback( this, param::k_iCallback ); } \
  157. CCallbackInternal_ ## func ( const CCallbackInternal_ ## func & ) { extra_code SteamAPI_RegisterCallback( this, param::k_iCallback ); } \
  158. CCallbackInternal_ ## func & operator=( const CCallbackInternal_ ## func & ) { return *this; } \
  159. private: virtual void Run( void *pvParam ) { _STEAM_CALLBACK_AUTO_HOOK( thisclass, func, param ) \
  160. thisclass *pOuter = reinterpret_cast<thisclass*>( reinterpret_cast<char*>(this) - offsetof( thisclass, m_steamcallback_ ## func ) ); \
  161. pOuter->func( reinterpret_cast<param*>( pvParam ) ); \
  162. } \
  163. } m_steamcallback_ ## func ; void func( param *pParam )
  164. #define _STEAM_CALLBACK_4( _, thisclass, func, param, var ) \
  165. CCallback< thisclass, param > var; void func( param *pParam )
  166. //-----------------------------------------------------------------------------
  167. // Purpose: maps a steam async call result to a class member function
  168. // template params: T = local class, P = parameter struct
  169. //-----------------------------------------------------------------------------
  170. template< class T, class P >
  171. inline CCallResult<T, P>::CCallResult()
  172. {
  173. m_hAPICall = k_uAPICallInvalid;
  174. m_pObj = NULL;
  175. m_Func = NULL;
  176. m_iCallback = P::k_iCallback;
  177. }
  178. template< class T, class P >
  179. inline void CCallResult<T, P>::Set( SteamAPICall_t hAPICall, T *p, func_t func )
  180. {
  181. if ( m_hAPICall )
  182. SteamAPI_UnregisterCallResult( this, m_hAPICall );
  183. m_hAPICall = hAPICall;
  184. m_pObj = p;
  185. m_Func = func;
  186. if ( hAPICall )
  187. SteamAPI_RegisterCallResult( this, hAPICall );
  188. }
  189. template< class T, class P >
  190. inline bool CCallResult<T, P>::IsActive() const
  191. {
  192. return (m_hAPICall != k_uAPICallInvalid);
  193. }
  194. template< class T, class P >
  195. inline void CCallResult<T, P>::Cancel()
  196. {
  197. if ( m_hAPICall != k_uAPICallInvalid )
  198. {
  199. SteamAPI_UnregisterCallResult( this, m_hAPICall );
  200. m_hAPICall = k_uAPICallInvalid;
  201. }
  202. }
  203. template< class T, class P >
  204. inline CCallResult<T, P>::~CCallResult()
  205. {
  206. Cancel();
  207. }
  208. template< class T, class P >
  209. inline void CCallResult<T, P>::Run( void *pvParam )
  210. {
  211. m_hAPICall = k_uAPICallInvalid; // caller unregisters for us
  212. (m_pObj->*m_Func)((P *)pvParam, false);
  213. }
  214. template< class T, class P >
  215. inline void CCallResult<T, P>::Run( void *pvParam, bool bIOFailure, SteamAPICall_t hSteamAPICall )
  216. {
  217. if ( hSteamAPICall == m_hAPICall )
  218. {
  219. m_hAPICall = k_uAPICallInvalid; // caller unregisters for us
  220. (m_pObj->*m_Func)((P *)pvParam, bIOFailure);
  221. }
  222. }
  223. //-----------------------------------------------------------------------------
  224. // Purpose: maps a steam callback to a class member function
  225. // template params: T = local class, P = parameter struct,
  226. // bGameserver = listen for gameserver callbacks instead of client callbacks
  227. //-----------------------------------------------------------------------------
  228. template< class T, class P, bool bGameserver >
  229. inline CCallback< T, P, bGameserver >::CCallback( T *pObj, func_t func )
  230. : m_pObj( NULL ), m_Func( NULL )
  231. {
  232. if ( bGameserver )
  233. {
  234. this->SetGameserverFlag();
  235. }
  236. Register( pObj, func );
  237. }
  238. template< class T, class P, bool bGameserver >
  239. inline void CCallback< T, P, bGameserver >::Register( T *pObj, func_t func )
  240. {
  241. if ( !pObj || !func )
  242. return;
  243. if ( this->m_nCallbackFlags & CCallbackBase::k_ECallbackFlagsRegistered )
  244. Unregister();
  245. m_pObj = pObj;
  246. m_Func = func;
  247. // SteamAPI_RegisterCallback sets k_ECallbackFlagsRegistered
  248. SteamAPI_RegisterCallback( this, P::k_iCallback );
  249. }
  250. template< class T, class P, bool bGameserver >
  251. inline void CCallback< T, P, bGameserver >::Unregister()
  252. {
  253. // SteamAPI_UnregisterCallback removes k_ECallbackFlagsRegistered
  254. SteamAPI_UnregisterCallback( this );
  255. }
  256. template< class T, class P, bool bGameserver >
  257. inline void CCallback< T, P, bGameserver >::Run( void *pvParam )
  258. {
  259. (m_pObj->*m_Func)((P *)pvParam);
  260. }
  261. #if defined(USE_BREAKPAD_HANDLER) || defined(STEAM_API_EXPORTS)
  262. // this should be called before the game initialized the steam APIs
  263. // pchDate should be of the format "Mmm dd yyyy" (such as from the __ DATE __ macro )
  264. // pchTime should be of the format "hh:mm:ss" (such as from the __ TIME __ macro )
  265. // bFullMemoryDumps (Win32 only) -- writes out a uuid-full.dmp in the client/dumps folder
  266. // pvContext-- can be NULL, will be the void * context passed into m_pfnPreMinidumpCallback
  267. // 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.
  268. S_API void S_CALLTYPE SteamAPI_UseBreakpadCrashHandler( char const *pchVersion, char const *pchDate, char const *pchTime, bool bFullMemoryDumps, void *pvContext, PFNPreMinidumpCallback m_pfnPreMinidumpCallback );
  269. S_API void S_CALLTYPE SteamAPI_SetBreakpadAppID( uint32 unAppID );
  270. #endif
  271. #endif // STEAM_API_INTERNAL_H