public/steam/isteamclient.h
author Nicholas Hastings <nshastings@gmail.com>
Sun Nov 03 09:37:43 2013 -0500 (2013-11-03)
changeset 29 e827f56d0c8f
permissions -rw-r--r--
Recompile linux and mac tier1.
[email protected]
     1
//========= Copyright Valve Corporation, All rights reserved. ============//
[email protected]
     2
//
[email protected]
     3
// Purpose: Main interface for loading and accessing Steamworks API's from the 
[email protected]
     4
//			Steam client.
[email protected]
     5
//			For most uses, this code is wrapped inside of SteamAPI_Init()
[email protected]
     6
//=============================================================================
[email protected]
     7
[email protected]
     8
#ifndef ISTEAMCLIENT_H
[email protected]
     9
#define ISTEAMCLIENT_H
[email protected]
    10
#ifdef _WIN32
[email protected]
    11
#pragma once
[email protected]
    12
#endif
[email protected]
    13
[email protected]
    14
#include "steamtypes.h"
[email protected]
    15
#include "steamclientpublic.h"
[email protected]
    16
[email protected]
    17
// Define compile time assert macros to let us validate the structure sizes.
[email protected]
    18
#define VALVE_COMPILE_TIME_ASSERT( pred ) typedef char compile_time_assert_type[(pred) ? 1 : -1];
[email protected]
    19
[email protected]
    20
#if defined(__linux__) || defined(__APPLE__) 
[email protected]
    21
// The 32-bit version of gcc has the alignment requirement for uint64 and double set to
[email protected]
    22
// 4 meaning that even with #pragma pack(8) these types will only be four-byte aligned.
[email protected]
    23
// The 64-bit version of gcc has the alignment requirement for these types set to
[email protected]
    24
// 8 meaning that unless we use #pragma pack(4) our structures will get bigger.
[email protected]
    25
// The 64-bit structure packing has to match the 32-bit structure packing for each platform.
[email protected]
    26
#define VALVE_CALLBACK_PACK_SMALL
[email protected]
    27
#else
[email protected]
    28
#define VALVE_CALLBACK_PACK_LARGE
[email protected]
    29
#endif
[email protected]
    30
[email protected]
    31
#if defined( VALVE_CALLBACK_PACK_SMALL )
[email protected]
    32
#pragma pack( push, 4 )
[email protected]
    33
#elif defined( VALVE_CALLBACK_PACK_LARGE )
[email protected]
    34
#pragma pack( push, 8 )
[email protected]
    35
#else
[email protected]
    36
#error ???
[email protected]
    37
#endif 
[email protected]
    38
[email protected]
    39
typedef struct
[email protected]
    40
{
[email protected]
    41
    uint32 m_u32;
[email protected]
    42
    uint64 m_u64;
[email protected]
    43
    uint16 m_u16;
[email protected]
    44
    double m_d;
[email protected]
    45
} ValvePackingSentinel_t;
[email protected]
    46
[email protected]
    47
#pragma pack( pop )
[email protected]
    48
[email protected]
    49
[email protected]
    50
#if defined(VALVE_CALLBACK_PACK_SMALL)
[email protected]
    51
VALVE_COMPILE_TIME_ASSERT( sizeof(ValvePackingSentinel_t) == 24 )
[email protected]
    52
#elif defined(VALVE_CALLBACK_PACK_LARGE)
[email protected]
    53
VALVE_COMPILE_TIME_ASSERT( sizeof(ValvePackingSentinel_t) == 32 )
[email protected]
    54
#else
[email protected]
    55
#error ???
[email protected]
    56
#endif
[email protected]
    57
[email protected]
    58
[email protected]
    59
// handle to a communication pipe to the Steam client
[email protected]
    60
typedef int32 HSteamPipe;
[email protected]
    61
// handle to single instance of a steam user
[email protected]
    62
typedef int32 HSteamUser;
[email protected]
    63
// function prototype
[email protected]
    64
#if defined( POSIX )
[email protected]
    65
#define __cdecl
[email protected]
    66
#endif
[email protected]
    67
extern "C" typedef void (__cdecl *SteamAPIWarningMessageHook_t)(int, const char *);
[email protected]
    68
[email protected]
    69
#if defined( __SNC__ )
[email protected]
    70
	#pragma diag_suppress=1700	   // warning 1700: class "%s" has virtual functions but non-virtual destructor
[email protected]
    71
#endif
[email protected]
    72
[email protected]
    73
// interface predec
[email protected]
    74
class ISteamUser;
[email protected]
    75
class ISteamGameServer;
[email protected]
    76
class ISteamFriends;
[email protected]
    77
class ISteamUtils;
[email protected]
    78
class ISteamMatchmaking;
[email protected]
    79
class ISteamContentServer;
[email protected]
    80
class ISteamMatchmakingServers;
[email protected]
    81
class ISteamUserStats;
[email protected]
    82
class ISteamApps;
[email protected]
    83
class ISteamNetworking;
[email protected]
    84
class ISteamRemoteStorage;
[email protected]
    85
class ISteamScreenshots;
[email protected]
    86
class ISteamGameServerStats;
[email protected]
    87
class ISteamPS3OverlayRender;
[email protected]
    88
class ISteamHTTP;
[email protected]
    89
class ISteamUnifiedMessages;
[email protected]
    90
[email protected]
    91
//-----------------------------------------------------------------------------
[email protected]
    92
// Purpose: Interface to creating a new steam instance, or to
[email protected]
    93
//			connect to an existing steam instance, whether it's in a
[email protected]
    94
//			different process or is local.
[email protected]
    95
//
[email protected]
    96
//			For most scenarios this is all handled automatically via SteamAPI_Init().
[email protected]
    97
//			You'll only need to use these interfaces if you have a more complex versioning scheme,
[email protected]
    98
//			where you want to get different versions of the same interface in different dll's in your project.
[email protected]
    99
//-----------------------------------------------------------------------------
joe[email protected]
   100
class ISteamClient
[email protected]
   101
{
[email protected]
   102
public:
[email protected]
   103
	// Creates a communication pipe to the Steam client
[email protected]
   104
	virtual HSteamPipe CreateSteamPipe() = 0;
[email protected]
   105
[email protected]
   106
	// Releases a previously created communications pipe
[email protected]
   107
	virtual bool BReleaseSteamPipe( HSteamPipe hSteamPipe ) = 0;
[email protected]
   108
[email protected]
   109
	// connects to an existing global user, failing if none exists
[email protected]
   110
	// used by the game to coordinate with the steamUI
[email protected]
   111
	virtual HSteamUser ConnectToGlobalUser( HSteamPipe hSteamPipe ) = 0;
[email protected]
   112
[email protected]
   113
	// used by game servers, create a steam user that won't be shared with anyone else
[email protected]
   114
	virtual HSteamUser CreateLocalUser( HSteamPipe *phSteamPipe, EAccountType eAccountType ) = 0;
[email protected]
   115
[email protected]
   116
	// removes an allocated user
[email protected]
   117
	virtual void ReleaseUser( HSteamPipe hSteamPipe, HSteamUser hUser ) = 0;
[email protected]
   118
[email protected]
   119
	// retrieves the ISteamUser interface associated with the handle
[email protected]
   120
	virtual ISteamUser *GetISteamUser( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
[email protected]
   121
[email protected]
   122
	// retrieves the ISteamGameServer interface associated with the handle
[email protected]
   123
	virtual ISteamGameServer *GetISteamGameServer( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
[email protected]
   124
[email protected]
   125
	// set the local IP and Port to bind to
[email protected]
   126
	// this must be set before CreateLocalUser()
[email protected]
   127
	virtual void SetLocalIPBinding( uint32 unIP, uint16 usPort ) = 0; 
[email protected]
   128
[email protected]
   129
	// returns the ISteamFriends interface
[email protected]
   130
	virtual ISteamFriends *GetISteamFriends( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
[email protected]
   131
[email protected]
   132
	// returns the ISteamUtils interface
[email protected]
   133
	virtual ISteamUtils *GetISteamUtils( HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
[email protected]
   134
[email protected]
   135
	// returns the ISteamMatchmaking interface
[email protected]
   136
	virtual ISteamMatchmaking *GetISteamMatchmaking( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
[email protected]
   137
[email protected]
   138
	// returns the ISteamMatchmakingServers interface
[email protected]
   139
	virtual ISteamMatchmakingServers *GetISteamMatchmakingServers( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
[email protected]
   140
[email protected]
   141
	// returns the a generic interface
[email protected]
   142
	virtual void *GetISteamGenericInterface( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
[email protected]
   143
[email protected]
   144
	// returns the ISteamUserStats interface
[email protected]
   145
	virtual ISteamUserStats *GetISteamUserStats( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
[email protected]
   146
[email protected]
   147
	// returns the ISteamGameServerStats interface
[email protected]
   148
	virtual ISteamGameServerStats *GetISteamGameServerStats( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
[email protected]
   149
[email protected]
   150
	// returns apps interface
[email protected]
   151
	virtual ISteamApps *GetISteamApps( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
[email protected]
   152
[email protected]
   153
	// networking
[email protected]
   154
	virtual ISteamNetworking *GetISteamNetworking( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
[email protected]
   155
[email protected]
   156
	// remote storage
[email protected]
   157
	virtual ISteamRemoteStorage *GetISteamRemoteStorage( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
[email protected]
   158
[email protected]
   159
	// user screenshots
[email protected]
   160
	virtual ISteamScreenshots *GetISteamScreenshots( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
[email protected]
   161
[email protected]
   162
[email protected]
   163
	// this needs to be called every frame to process matchmaking results
[email protected]
   164
	// redundant if you're already calling SteamAPI_RunCallbacks()
[email protected]
   165
	virtual void RunFrame() = 0;
[email protected]
   166
[email protected]
   167
	// returns the number of IPC calls made since the last time this function was called
[email protected]
   168
	// Used for perf debugging so you can understand how many IPC calls your game makes per frame
[email protected]
   169
	// Every IPC call is at minimum a thread context switch if not a process one so you want to rate
[email protected]
   170
	// control how often you do them.
[email protected]
   171
	virtual uint32 GetIPCCallCount() = 0;
[email protected]
   172
[email protected]
   173
	// API warning handling
[email protected]
   174
	// 'int' is the severity; 0 for msg, 1 for warning
[email protected]
   175
	// 'const char *' is the text of the message
[email protected]
   176
	// callbacks will occur directly after the API function is called that generated the warning or message
[email protected]
   177
	virtual void SetWarningMessageHook( SteamAPIWarningMessageHook_t pFunction ) = 0;
[email protected]
   178
[email protected]
   179
	// Trigger global shutdown for the DLL
[email protected]
   180
	virtual bool BShutdownIfAllPipesClosed() = 0;
[email protected]
   181
[email protected]
   182
#ifdef _PS3
[email protected]
   183
	virtual ISteamPS3OverlayRender *GetISteamPS3OverlayRender() = 0;
[email protected]
   184
#endif
[email protected]
   185
[email protected]
   186
	// Expose HTTP interface
[email protected]
   187
	virtual ISteamHTTP *GetISteamHTTP( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
[email protected]
   188
[email protected]
   189
	// Exposes the ISteamUnifiedMessages interface
[email protected]
   190
	virtual ISteamUnifiedMessages *GetISteamUnifiedMessages( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
[email protected]
   191
[email protected]
   192
};
[email protected]
   193
[email protected]
   194
#define STEAMCLIENT_INTERFACE_VERSION		"SteamClient012"
[email protected]
   195
[email protected]
   196
//-----------------------------------------------------------------------------
[email protected]
   197
// Purpose: Base values for callback identifiers, each callback must
[email protected]
   198
//			have a unique ID.
[email protected]
   199
//-----------------------------------------------------------------------------
[email protected]
   200
enum { k_iSteamUserCallbacks = 100 };
[email protected]
   201
enum { k_iSteamGameServerCallbacks = 200 };
[email protected]
   202
enum { k_iSteamFriendsCallbacks = 300 };
[email protected]
   203
enum { k_iSteamBillingCallbacks = 400 };
[email protected]
   204
enum { k_iSteamMatchmakingCallbacks = 500 };
[email protected]
   205
enum { k_iSteamContentServerCallbacks = 600 };
[email protected]
   206
enum { k_iSteamUtilsCallbacks = 700 };
[email protected]
   207
enum { k_iClientFriendsCallbacks = 800 };
[email protected]
   208
enum { k_iClientUserCallbacks = 900 };
[email protected]
   209
enum { k_iSteamAppsCallbacks = 1000 };
[email protected]
   210
enum { k_iSteamUserStatsCallbacks = 1100 };
[email protected]
   211
enum { k_iSteamNetworkingCallbacks = 1200 };
[email protected]
   212
enum { k_iClientRemoteStorageCallbacks = 1300 };
[email protected]
   213
enum { k_iSteamUserItemsCallbacks = 1400 };
[email protected]
   214
enum { k_iSteamGameServerItemsCallbacks = 1500 };
[email protected]
   215
enum { k_iClientUtilsCallbacks = 1600 };
[email protected]
   216
enum { k_iSteamGameCoordinatorCallbacks = 1700 };
[email protected]
   217
enum { k_iSteamGameServerStatsCallbacks = 1800 };
[email protected]
   218
enum { k_iSteam2AsyncCallbacks = 1900 };
[email protected]
   219
enum { k_iSteamGameStatsCallbacks = 2000 };
[email protected]
   220
enum { k_iClientHTTPCallbacks = 2100 };
[email protected]
   221
enum { k_iClientScreenshotsCallbacks = 2200 };
[email protected]
   222
enum { k_iSteamScreenshotsCallbacks = 2300 };
[email protected]
   223
enum { k_iClientAudioCallbacks = 2400 };
[email protected]
   224
enum { k_iClientUnifiedMessagesCallbacks = 2500 };
[email protected]
   225
enum { k_iSteamStreamLauncherCallbacks = 2600 };
[email protected]
   226
enum { k_iClientControllerCallbacks = 2700 };
[email protected]
   227
enum { k_iSteamControllerCallbacks = 2800 };
[email protected]
   228
enum { k_iClientParentalSettingsCallbacks = 2900 };
[email protected]
   229
enum { k_iClientDeviceAuthCallbacks = 3000 };
[email protected]
   230
enum { k_iClientNetworkDeviceManagerCallbacks = 3100 };
[email protected]
   231
[email protected]
   232
[email protected]
   233
//-----------------------------------------------------------------------------
[email protected]
   234
// The CALLBACK macros are for client side callback logging enabled with
[email protected]
   235
// log_callback <first callnbackID> <last callbackID>
[email protected]
   236
// Do not change any of these. 
[email protected]
   237
//-----------------------------------------------------------------------------
[email protected]
   238
[email protected]
   239
class CSteamCallback
[email protected]
   240
{
[email protected]
   241
public:
[email protected]
   242
	virtual const char *GetCallbackName() const = 0;
[email protected]
   243
	virtual uint32 GetCallbackID() const = 0;
[email protected]
   244
	virtual uint8 *GetFixedData() const = 0;
[email protected]
   245
	virtual uint32 GetFixedSize() const = 0;
[email protected]
   246
	virtual uint32 GetNumMemberVariables() const = 0;
[email protected]
   247
	virtual bool GetMemberVariable( uint32 index, uint32 &varOffset, uint32 &varSize, uint32 &varCount, const char **pszName, const char **pszType  ) const = 0;
[email protected]
   248
};
[email protected]
   249
[email protected]
   250
#define DEFINE_CALLBACK( callbackname, callbackid ) \
[email protected]
   251
struct callbackname##_t { \
[email protected]
   252
	enum { k_iCallback = callbackid }; \
[email protected]
   253
	static callbackname##_t *GetNullPointer() { return 0; }
jo[email protected]
   254
[email protected]
   255
#define CALLBACK_MEMBER( varidx, vartype, varname ) \
[email protected]
   256
	public: vartype varname ; \
[email protected]
   257
	static void GetMemberVar_##varidx( unsigned int &varOffset, unsigned int &varSize, uint32 &varCount, const char **pszName, const char **pszType ) { \
[email protected]
   258
			varOffset = (unsigned int)(size_t)&GetNullPointer()->varname; \
[email protected]
   259
			varSize = sizeof( vartype ); \
[email protected]
   260
			varCount = 1; \
[email protected]
   261
			*pszName = #varname; *pszType = #vartype; }
[email protected]
   262
[email protected]
   263
#define CALLBACK_ARRAY( varidx, vartype, varname, varcount ) \
[email protected]
   264
	public: vartype varname [ varcount ]; \
[email protected]
   265
	static void GetMemberVar_##varidx( unsigned int &varOffset, unsigned int &varSize, uint32 &varCount, const char **pszName, const char **pszType ) { \
[email protected]
   266
	varOffset = (unsigned int)(size_t)&GetNullPointer()->varname[0]; \
[email protected]
   267
	varSize = sizeof( vartype ); \
[email protected]
   268
	varCount = varcount; \
[email protected]
   269
	*pszName = #varname; *pszType = #vartype; }
[email protected]
   270
[email protected]
   271
[email protected]
   272
#define END_CALLBACK_INTERNAL_BEGIN( callbackname, numvars )  }; \
[email protected]
   273
class C##callbackname : public CSteamCallback { \
[email protected]
   274
public: callbackname##_t m_Data; \
[email protected]
   275
	C##callbackname () { memset( &m_Data, 0, sizeof(m_Data) ); } \
[email protected]
   276
	virtual const char *GetCallbackName() const { return #callbackname; } \
[email protected]
   277
	virtual uint32  GetCallbackID() const { return callbackname##_t::k_iCallback; } \
[email protected]
   278
	virtual uint32  GetFixedSize() const { return sizeof( m_Data ); } \
[email protected]
   279
	virtual uint8  *GetFixedData() const { return (uint8*)&m_Data; } \
[email protected]
   280
	virtual uint32  GetNumMemberVariables() const { return numvars; } \
[email protected]
   281
	virtual bool    GetMemberVariable( uint32 index, uint32 &varOffset, uint32 &varSize,  uint32 &varCount, const char **pszName, const char **pszType ) const { \
[email protected]
   282
	switch ( index ) { default : return false;
[email protected]
   283
[email protected]
   284
[email protected]
   285
#define END_CALLBACK_INTERNAL_SWITCH( varidx ) case varidx : m_Data.GetMemberVar_##varidx( varOffset, varSize, varCount, pszName, pszType ); return true;
[email protected]
   286
[email protected]
   287
#define END_CALLBACK_INTERNAL_END() }; }; };
[email protected]
   288
[email protected]
   289
#define END_DEFINE_CALLBACK_0( callbackname )  }; \
[email protected]
   290
class C##callbackname : public CSteamCallback { \
[email protected]
   291
public: callbackname##_t m_Data; \
[email protected]
   292
	virtual const char *GetCallbackName() const { return #callbackname; } \
[email protected]
   293
	virtual uint32  GetCallbackID() const { return callbackname##_t::k_iCallback; } \
[email protected]
   294
	virtual uint32  GetFixedSize() const { return sizeof( m_Data ); } \
[email protected]
   295
	virtual uint8  *GetFixedData() const { return (uint8*)&m_Data; } \
[email protected]
   296
	virtual uint32  GetNumMemberVariables() const { return 0; } \
[email protected]
   297
	virtual bool    GetMemberVariable( uint32 index, uint32 &varOffset, uint32 &varSize,  uint32 &varCount, const char **pszName, const char **pszType ) const { return false; } \
[email protected]
   298
	}; \
[email protected]
   299
	
[email protected]
   300
[email protected]
   301
#define END_DEFINE_CALLBACK_1( callbackname ) \
[email protected]
   302
	END_CALLBACK_INTERNAL_BEGIN( callbackname, 1 ) \
[email protected]
   303
	END_CALLBACK_INTERNAL_SWITCH( 0 ) \
[email protected]
   304
	END_CALLBACK_INTERNAL_END()
[email protected]
   305
[email protected]
   306
#define END_DEFINE_CALLBACK_2( callbackname ) \
[email protected]
   307
	END_CALLBACK_INTERNAL_BEGIN( callbackname, 2 ) \
[email protected]
   308
	END_CALLBACK_INTERNAL_SWITCH( 0 ) \
[email protected]
   309
	END_CALLBACK_INTERNAL_SWITCH( 1 ) \
[email protected]
   310
	END_CALLBACK_INTERNAL_END()
[email protected]
   311
[email protected]
   312
#define END_DEFINE_CALLBACK_3( callbackname ) \
[email protected]
   313
	END_CALLBACK_INTERNAL_BEGIN( callbackname, 3 ) \
[email protected]
   314
	END_CALLBACK_INTERNAL_SWITCH( 0 ) \
[email protected]
   315
	END_CALLBACK_INTERNAL_SWITCH( 1 ) \
[email protected]
   316
	END_CALLBACK_INTERNAL_SWITCH( 2 ) \
[email protected]
   317
	END_CALLBACK_INTERNAL_END()
[email protected]
   318
[email protected]
   319
#define END_DEFINE_CALLBACK_4( callbackname ) \
[email protected]
   320
	END_CALLBACK_INTERNAL_BEGIN( callbackname, 4 ) \
[email protected]
   321
	END_CALLBACK_INTERNAL_SWITCH( 0 ) \
[email protected]
   322
	END_CALLBACK_INTERNAL_SWITCH( 1 ) \
[email protected]
   323
	END_CALLBACK_INTERNAL_SWITCH( 2 ) \
[email protected]
   324
	END_CALLBACK_INTERNAL_SWITCH( 3 ) \
[email protected]
   325
	END_CALLBACK_INTERNAL_END()
[email protected]
   326
[email protected]
   327
[email protected]
   328
#define END_DEFINE_CALLBACK_6( callbackname ) \
[email protected]
   329
	END_CALLBACK_INTERNAL_BEGIN( callbackname, 6 ) \
[email protected]
   330
	END_CALLBACK_INTERNAL_SWITCH( 0 ) \
[email protected]
   331
	END_CALLBACK_INTERNAL_SWITCH( 1 ) \
[email protected]
   332
	END_CALLBACK_INTERNAL_SWITCH( 2 ) \
[email protected]
   333
	END_CALLBACK_INTERNAL_SWITCH( 3 ) \
[email protected]
   334
	END_CALLBACK_INTERNAL_SWITCH( 4 ) \
[email protected]
   335
	END_CALLBACK_INTERNAL_SWITCH( 5 ) \
[email protected]
   336
	END_CALLBACK_INTERNAL_END()
[email protected]
   337
[email protected]
   338
#define END_DEFINE_CALLBACK_7( callbackname ) \
[email protected]
   339
	END_CALLBACK_INTERNAL_BEGIN( callbackname, 7 ) \
[email protected]
   340
	END_CALLBACK_INTERNAL_SWITCH( 0 ) \
[email protected]
   341
	END_CALLBACK_INTERNAL_SWITCH( 1 ) \
[email protected]
   342
	END_CALLBACK_INTERNAL_SWITCH( 2 ) \
[email protected]
   343
	END_CALLBACK_INTERNAL_SWITCH( 3 ) \
[email protected]
   344
	END_CALLBACK_INTERNAL_SWITCH( 4 ) \
[email protected]
   345
	END_CALLBACK_INTERNAL_SWITCH( 5 ) \
[email protected]
   346
	END_CALLBACK_INTERNAL_SWITCH( 6 ) \
[email protected]
   347
	END_CALLBACK_INTERNAL_END()
[email protected]
   348
[email protected]
   349
#endif // ISTEAMCLIENT_H