public/steam/isteamclient.h
changeset 0 96a5fce1fd6f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/public/steam/isteamclient.h	Wed Jun 26 15:22:04 2013 -0700
     1.3 @@ -0,0 +1,349 @@
     1.4 +//========= Copyright Valve Corporation, All rights reserved. ============//
     1.5 +//
     1.6 +// Purpose: Main interface for loading and accessing Steamworks API's from the 
     1.7 +//			Steam client.
     1.8 +//			For most uses, this code is wrapped inside of SteamAPI_Init()
     1.9 +//=============================================================================
    1.10 +
    1.11 +#ifndef ISTEAMCLIENT_H
    1.12 +#define ISTEAMCLIENT_H
    1.13 +#ifdef _WIN32
    1.14 +#pragma once
    1.15 +#endif
    1.16 +
    1.17 +#include "steamtypes.h"
    1.18 +#include "steamclientpublic.h"
    1.19 +
    1.20 +// Define compile time assert macros to let us validate the structure sizes.
    1.21 +#define VALVE_COMPILE_TIME_ASSERT( pred ) typedef char compile_time_assert_type[(pred) ? 1 : -1];
    1.22 +
    1.23 +#if defined(__linux__) || defined(__APPLE__) 
    1.24 +// The 32-bit version of gcc has the alignment requirement for uint64 and double set to
    1.25 +// 4 meaning that even with #pragma pack(8) these types will only be four-byte aligned.
    1.26 +// The 64-bit version of gcc has the alignment requirement for these types set to
    1.27 +// 8 meaning that unless we use #pragma pack(4) our structures will get bigger.
    1.28 +// The 64-bit structure packing has to match the 32-bit structure packing for each platform.
    1.29 +#define VALVE_CALLBACK_PACK_SMALL
    1.30 +#else
    1.31 +#define VALVE_CALLBACK_PACK_LARGE
    1.32 +#endif
    1.33 +
    1.34 +#if defined( VALVE_CALLBACK_PACK_SMALL )
    1.35 +#pragma pack( push, 4 )
    1.36 +#elif defined( VALVE_CALLBACK_PACK_LARGE )
    1.37 +#pragma pack( push, 8 )
    1.38 +#else
    1.39 +#error ???
    1.40 +#endif 
    1.41 +
    1.42 +typedef struct
    1.43 +{
    1.44 +    uint32 m_u32;
    1.45 +    uint64 m_u64;
    1.46 +    uint16 m_u16;
    1.47 +    double m_d;
    1.48 +} ValvePackingSentinel_t;
    1.49 +
    1.50 +#pragma pack( pop )
    1.51 +
    1.52 +
    1.53 +#if defined(VALVE_CALLBACK_PACK_SMALL)
    1.54 +VALVE_COMPILE_TIME_ASSERT( sizeof(ValvePackingSentinel_t) == 24 )
    1.55 +#elif defined(VALVE_CALLBACK_PACK_LARGE)
    1.56 +VALVE_COMPILE_TIME_ASSERT( sizeof(ValvePackingSentinel_t) == 32 )
    1.57 +#else
    1.58 +#error ???
    1.59 +#endif
    1.60 +
    1.61 +
    1.62 +// handle to a communication pipe to the Steam client
    1.63 +typedef int32 HSteamPipe;
    1.64 +// handle to single instance of a steam user
    1.65 +typedef int32 HSteamUser;
    1.66 +// function prototype
    1.67 +#if defined( POSIX )
    1.68 +#define __cdecl
    1.69 +#endif
    1.70 +extern "C" typedef void (__cdecl *SteamAPIWarningMessageHook_t)(int, const char *);
    1.71 +
    1.72 +#if defined( __SNC__ )
    1.73 +	#pragma diag_suppress=1700	   // warning 1700: class "%s" has virtual functions but non-virtual destructor
    1.74 +#endif
    1.75 +
    1.76 +// interface predec
    1.77 +class ISteamUser;
    1.78 +class ISteamGameServer;
    1.79 +class ISteamFriends;
    1.80 +class ISteamUtils;
    1.81 +class ISteamMatchmaking;
    1.82 +class ISteamContentServer;
    1.83 +class ISteamMatchmakingServers;
    1.84 +class ISteamUserStats;
    1.85 +class ISteamApps;
    1.86 +class ISteamNetworking;
    1.87 +class ISteamRemoteStorage;
    1.88 +class ISteamScreenshots;
    1.89 +class ISteamGameServerStats;
    1.90 +class ISteamPS3OverlayRender;
    1.91 +class ISteamHTTP;
    1.92 +class ISteamUnifiedMessages;
    1.93 +
    1.94 +//-----------------------------------------------------------------------------
    1.95 +// Purpose: Interface to creating a new steam instance, or to
    1.96 +//			connect to an existing steam instance, whether it's in a
    1.97 +//			different process or is local.
    1.98 +//
    1.99 +//			For most scenarios this is all handled automatically via SteamAPI_Init().
   1.100 +//			You'll only need to use these interfaces if you have a more complex versioning scheme,
   1.101 +//			where you want to get different versions of the same interface in different dll's in your project.
   1.102 +//-----------------------------------------------------------------------------
   1.103 +class ISteamClient
   1.104 +{
   1.105 +public:
   1.106 +	// Creates a communication pipe to the Steam client
   1.107 +	virtual HSteamPipe CreateSteamPipe() = 0;
   1.108 +
   1.109 +	// Releases a previously created communications pipe
   1.110 +	virtual bool BReleaseSteamPipe( HSteamPipe hSteamPipe ) = 0;
   1.111 +
   1.112 +	// connects to an existing global user, failing if none exists
   1.113 +	// used by the game to coordinate with the steamUI
   1.114 +	virtual HSteamUser ConnectToGlobalUser( HSteamPipe hSteamPipe ) = 0;
   1.115 +
   1.116 +	// used by game servers, create a steam user that won't be shared with anyone else
   1.117 +	virtual HSteamUser CreateLocalUser( HSteamPipe *phSteamPipe, EAccountType eAccountType ) = 0;
   1.118 +
   1.119 +	// removes an allocated user
   1.120 +	virtual void ReleaseUser( HSteamPipe hSteamPipe, HSteamUser hUser ) = 0;
   1.121 +
   1.122 +	// retrieves the ISteamUser interface associated with the handle
   1.123 +	virtual ISteamUser *GetISteamUser( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   1.124 +
   1.125 +	// retrieves the ISteamGameServer interface associated with the handle
   1.126 +	virtual ISteamGameServer *GetISteamGameServer( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   1.127 +
   1.128 +	// set the local IP and Port to bind to
   1.129 +	// this must be set before CreateLocalUser()
   1.130 +	virtual void SetLocalIPBinding( uint32 unIP, uint16 usPort ) = 0; 
   1.131 +
   1.132 +	// returns the ISteamFriends interface
   1.133 +	virtual ISteamFriends *GetISteamFriends( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   1.134 +
   1.135 +	// returns the ISteamUtils interface
   1.136 +	virtual ISteamUtils *GetISteamUtils( HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   1.137 +
   1.138 +	// returns the ISteamMatchmaking interface
   1.139 +	virtual ISteamMatchmaking *GetISteamMatchmaking( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   1.140 +
   1.141 +	// returns the ISteamMatchmakingServers interface
   1.142 +	virtual ISteamMatchmakingServers *GetISteamMatchmakingServers( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   1.143 +
   1.144 +	// returns the a generic interface
   1.145 +	virtual void *GetISteamGenericInterface( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   1.146 +
   1.147 +	// returns the ISteamUserStats interface
   1.148 +	virtual ISteamUserStats *GetISteamUserStats( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   1.149 +
   1.150 +	// returns the ISteamGameServerStats interface
   1.151 +	virtual ISteamGameServerStats *GetISteamGameServerStats( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   1.152 +
   1.153 +	// returns apps interface
   1.154 +	virtual ISteamApps *GetISteamApps( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   1.155 +
   1.156 +	// networking
   1.157 +	virtual ISteamNetworking *GetISteamNetworking( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   1.158 +
   1.159 +	// remote storage
   1.160 +	virtual ISteamRemoteStorage *GetISteamRemoteStorage( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   1.161 +
   1.162 +	// user screenshots
   1.163 +	virtual ISteamScreenshots *GetISteamScreenshots( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   1.164 +
   1.165 +
   1.166 +	// this needs to be called every frame to process matchmaking results
   1.167 +	// redundant if you're already calling SteamAPI_RunCallbacks()
   1.168 +	virtual void RunFrame() = 0;
   1.169 +
   1.170 +	// returns the number of IPC calls made since the last time this function was called
   1.171 +	// Used for perf debugging so you can understand how many IPC calls your game makes per frame
   1.172 +	// Every IPC call is at minimum a thread context switch if not a process one so you want to rate
   1.173 +	// control how often you do them.
   1.174 +	virtual uint32 GetIPCCallCount() = 0;
   1.175 +
   1.176 +	// API warning handling
   1.177 +	// 'int' is the severity; 0 for msg, 1 for warning
   1.178 +	// 'const char *' is the text of the message
   1.179 +	// callbacks will occur directly after the API function is called that generated the warning or message
   1.180 +	virtual void SetWarningMessageHook( SteamAPIWarningMessageHook_t pFunction ) = 0;
   1.181 +
   1.182 +	// Trigger global shutdown for the DLL
   1.183 +	virtual bool BShutdownIfAllPipesClosed() = 0;
   1.184 +
   1.185 +#ifdef _PS3
   1.186 +	virtual ISteamPS3OverlayRender *GetISteamPS3OverlayRender() = 0;
   1.187 +#endif
   1.188 +
   1.189 +	// Expose HTTP interface
   1.190 +	virtual ISteamHTTP *GetISteamHTTP( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   1.191 +
   1.192 +	// Exposes the ISteamUnifiedMessages interface
   1.193 +	virtual ISteamUnifiedMessages *GetISteamUnifiedMessages( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   1.194 +
   1.195 +};
   1.196 +
   1.197 +#define STEAMCLIENT_INTERFACE_VERSION		"SteamClient012"
   1.198 +
   1.199 +//-----------------------------------------------------------------------------
   1.200 +// Purpose: Base values for callback identifiers, each callback must
   1.201 +//			have a unique ID.
   1.202 +//-----------------------------------------------------------------------------
   1.203 +enum { k_iSteamUserCallbacks = 100 };
   1.204 +enum { k_iSteamGameServerCallbacks = 200 };
   1.205 +enum { k_iSteamFriendsCallbacks = 300 };
   1.206 +enum { k_iSteamBillingCallbacks = 400 };
   1.207 +enum { k_iSteamMatchmakingCallbacks = 500 };
   1.208 +enum { k_iSteamContentServerCallbacks = 600 };
   1.209 +enum { k_iSteamUtilsCallbacks = 700 };
   1.210 +enum { k_iClientFriendsCallbacks = 800 };
   1.211 +enum { k_iClientUserCallbacks = 900 };
   1.212 +enum { k_iSteamAppsCallbacks = 1000 };
   1.213 +enum { k_iSteamUserStatsCallbacks = 1100 };
   1.214 +enum { k_iSteamNetworkingCallbacks = 1200 };
   1.215 +enum { k_iClientRemoteStorageCallbacks = 1300 };
   1.216 +enum { k_iSteamUserItemsCallbacks = 1400 };
   1.217 +enum { k_iSteamGameServerItemsCallbacks = 1500 };
   1.218 +enum { k_iClientUtilsCallbacks = 1600 };
   1.219 +enum { k_iSteamGameCoordinatorCallbacks = 1700 };
   1.220 +enum { k_iSteamGameServerStatsCallbacks = 1800 };
   1.221 +enum { k_iSteam2AsyncCallbacks = 1900 };
   1.222 +enum { k_iSteamGameStatsCallbacks = 2000 };
   1.223 +enum { k_iClientHTTPCallbacks = 2100 };
   1.224 +enum { k_iClientScreenshotsCallbacks = 2200 };
   1.225 +enum { k_iSteamScreenshotsCallbacks = 2300 };
   1.226 +enum { k_iClientAudioCallbacks = 2400 };
   1.227 +enum { k_iClientUnifiedMessagesCallbacks = 2500 };
   1.228 +enum { k_iSteamStreamLauncherCallbacks = 2600 };
   1.229 +enum { k_iClientControllerCallbacks = 2700 };
   1.230 +enum { k_iSteamControllerCallbacks = 2800 };
   1.231 +enum { k_iClientParentalSettingsCallbacks = 2900 };
   1.232 +enum { k_iClientDeviceAuthCallbacks = 3000 };
   1.233 +enum { k_iClientNetworkDeviceManagerCallbacks = 3100 };
   1.234 +
   1.235 +
   1.236 +//-----------------------------------------------------------------------------
   1.237 +// The CALLBACK macros are for client side callback logging enabled with
   1.238 +// log_callback <first callnbackID> <last callbackID>
   1.239 +// Do not change any of these. 
   1.240 +//-----------------------------------------------------------------------------
   1.241 +
   1.242 +class CSteamCallback
   1.243 +{
   1.244 +public:
   1.245 +	virtual const char *GetCallbackName() const = 0;
   1.246 +	virtual uint32 GetCallbackID() const = 0;
   1.247 +	virtual uint8 *GetFixedData() const = 0;
   1.248 +	virtual uint32 GetFixedSize() const = 0;
   1.249 +	virtual uint32 GetNumMemberVariables() const = 0;
   1.250 +	virtual bool GetMemberVariable( uint32 index, uint32 &varOffset, uint32 &varSize, uint32 &varCount, const char **pszName, const char **pszType  ) const = 0;
   1.251 +};
   1.252 +
   1.253 +#define DEFINE_CALLBACK( callbackname, callbackid ) \
   1.254 +struct callbackname##_t { \
   1.255 +	enum { k_iCallback = callbackid }; \
   1.256 +	static callbackname##_t *GetNullPointer() { return 0; }
   1.257 +
   1.258 +#define CALLBACK_MEMBER( varidx, vartype, varname ) \
   1.259 +	public: vartype varname ; \
   1.260 +	static void GetMemberVar_##varidx( unsigned int &varOffset, unsigned int &varSize, uint32 &varCount, const char **pszName, const char **pszType ) { \
   1.261 +			varOffset = (unsigned int)(size_t)&GetNullPointer()->varname; \
   1.262 +			varSize = sizeof( vartype ); \
   1.263 +			varCount = 1; \
   1.264 +			*pszName = #varname; *pszType = #vartype; }
   1.265 +
   1.266 +#define CALLBACK_ARRAY( varidx, vartype, varname, varcount ) \
   1.267 +	public: vartype varname [ varcount ]; \
   1.268 +	static void GetMemberVar_##varidx( unsigned int &varOffset, unsigned int &varSize, uint32 &varCount, const char **pszName, const char **pszType ) { \
   1.269 +	varOffset = (unsigned int)(size_t)&GetNullPointer()->varname[0]; \
   1.270 +	varSize = sizeof( vartype ); \
   1.271 +	varCount = varcount; \
   1.272 +	*pszName = #varname; *pszType = #vartype; }
   1.273 +
   1.274 +
   1.275 +#define END_CALLBACK_INTERNAL_BEGIN( callbackname, numvars )  }; \
   1.276 +class C##callbackname : public CSteamCallback { \
   1.277 +public: callbackname##_t m_Data; \
   1.278 +	C##callbackname () { memset( &m_Data, 0, sizeof(m_Data) ); } \
   1.279 +	virtual const char *GetCallbackName() const { return #callbackname; } \
   1.280 +	virtual uint32  GetCallbackID() const { return callbackname##_t::k_iCallback; } \
   1.281 +	virtual uint32  GetFixedSize() const { return sizeof( m_Data ); } \
   1.282 +	virtual uint8  *GetFixedData() const { return (uint8*)&m_Data; } \
   1.283 +	virtual uint32  GetNumMemberVariables() const { return numvars; } \
   1.284 +	virtual bool    GetMemberVariable( uint32 index, uint32 &varOffset, uint32 &varSize,  uint32 &varCount, const char **pszName, const char **pszType ) const { \
   1.285 +	switch ( index ) { default : return false;
   1.286 +
   1.287 +
   1.288 +#define END_CALLBACK_INTERNAL_SWITCH( varidx ) case varidx : m_Data.GetMemberVar_##varidx( varOffset, varSize, varCount, pszName, pszType ); return true;
   1.289 +
   1.290 +#define END_CALLBACK_INTERNAL_END() }; }; };
   1.291 +
   1.292 +#define END_DEFINE_CALLBACK_0( callbackname )  }; \
   1.293 +class C##callbackname : public CSteamCallback { \
   1.294 +public: callbackname##_t m_Data; \
   1.295 +	virtual const char *GetCallbackName() const { return #callbackname; } \
   1.296 +	virtual uint32  GetCallbackID() const { return callbackname##_t::k_iCallback; } \
   1.297 +	virtual uint32  GetFixedSize() const { return sizeof( m_Data ); } \
   1.298 +	virtual uint8  *GetFixedData() const { return (uint8*)&m_Data; } \
   1.299 +	virtual uint32  GetNumMemberVariables() const { return 0; } \
   1.300 +	virtual bool    GetMemberVariable( uint32 index, uint32 &varOffset, uint32 &varSize,  uint32 &varCount, const char **pszName, const char **pszType ) const { return false; } \
   1.301 +	}; \
   1.302 +	
   1.303 +
   1.304 +#define END_DEFINE_CALLBACK_1( callbackname ) \
   1.305 +	END_CALLBACK_INTERNAL_BEGIN( callbackname, 1 ) \
   1.306 +	END_CALLBACK_INTERNAL_SWITCH( 0 ) \
   1.307 +	END_CALLBACK_INTERNAL_END()
   1.308 +
   1.309 +#define END_DEFINE_CALLBACK_2( callbackname ) \
   1.310 +	END_CALLBACK_INTERNAL_BEGIN( callbackname, 2 ) \
   1.311 +	END_CALLBACK_INTERNAL_SWITCH( 0 ) \
   1.312 +	END_CALLBACK_INTERNAL_SWITCH( 1 ) \
   1.313 +	END_CALLBACK_INTERNAL_END()
   1.314 +
   1.315 +#define END_DEFINE_CALLBACK_3( callbackname ) \
   1.316 +	END_CALLBACK_INTERNAL_BEGIN( callbackname, 3 ) \
   1.317 +	END_CALLBACK_INTERNAL_SWITCH( 0 ) \
   1.318 +	END_CALLBACK_INTERNAL_SWITCH( 1 ) \
   1.319 +	END_CALLBACK_INTERNAL_SWITCH( 2 ) \
   1.320 +	END_CALLBACK_INTERNAL_END()
   1.321 +
   1.322 +#define END_DEFINE_CALLBACK_4( callbackname ) \
   1.323 +	END_CALLBACK_INTERNAL_BEGIN( callbackname, 4 ) \
   1.324 +	END_CALLBACK_INTERNAL_SWITCH( 0 ) \
   1.325 +	END_CALLBACK_INTERNAL_SWITCH( 1 ) \
   1.326 +	END_CALLBACK_INTERNAL_SWITCH( 2 ) \
   1.327 +	END_CALLBACK_INTERNAL_SWITCH( 3 ) \
   1.328 +	END_CALLBACK_INTERNAL_END()
   1.329 +
   1.330 +
   1.331 +#define END_DEFINE_CALLBACK_6( callbackname ) \
   1.332 +	END_CALLBACK_INTERNAL_BEGIN( callbackname, 6 ) \
   1.333 +	END_CALLBACK_INTERNAL_SWITCH( 0 ) \
   1.334 +	END_CALLBACK_INTERNAL_SWITCH( 1 ) \
   1.335 +	END_CALLBACK_INTERNAL_SWITCH( 2 ) \
   1.336 +	END_CALLBACK_INTERNAL_SWITCH( 3 ) \
   1.337 +	END_CALLBACK_INTERNAL_SWITCH( 4 ) \
   1.338 +	END_CALLBACK_INTERNAL_SWITCH( 5 ) \
   1.339 +	END_CALLBACK_INTERNAL_END()
   1.340 +
   1.341 +#define END_DEFINE_CALLBACK_7( callbackname ) \
   1.342 +	END_CALLBACK_INTERNAL_BEGIN( callbackname, 7 ) \
   1.343 +	END_CALLBACK_INTERNAL_SWITCH( 0 ) \
   1.344 +	END_CALLBACK_INTERNAL_SWITCH( 1 ) \
   1.345 +	END_CALLBACK_INTERNAL_SWITCH( 2 ) \
   1.346 +	END_CALLBACK_INTERNAL_SWITCH( 3 ) \
   1.347 +	END_CALLBACK_INTERNAL_SWITCH( 4 ) \
   1.348 +	END_CALLBACK_INTERNAL_SWITCH( 5 ) \
   1.349 +	END_CALLBACK_INTERNAL_SWITCH( 6 ) \
   1.350 +	END_CALLBACK_INTERNAL_END()
   1.351 +
   1.352 +#endif // ISTEAMCLIENT_H