Advertisement
Guest User

Untitled

a guest
Jun 4th, 2017
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. #include "Steamworks.h"
  2.  
  3. #include <iostream>
  4. #include <iomanip>
  5.  
  6. void ShowError( TSteamError *err )
  7. {
  8. if ( !IS_STEAM_ERROR( (*err) ) )
  9. return;
  10.  
  11. printf("Error: %s\n", err->szDesc);
  12.  
  13. getchar();
  14.  
  15. exit( 0 );
  16. }
  17.  
  18. int main()
  19. {
  20. void* steam_library = dlopen("libsteam.so", RTLD_LAZY);
  21. FactoryFn fn = (FactoryFn)dlsym(steam_library, "_f");
  22. dlclose(steam_library);
  23.  
  24. ISteam006 *steam = (ISteam006*)fn( "Steam006" );
  25. if ( !steam )
  26. {
  27. printf("Unable to get ISteam006.\n");
  28. return 0;
  29. }
  30.  
  31. TSteamError error;
  32.  
  33. // Either of these work, the difference and params for Ex are unknown.
  34. //if ( !steam->StartEngine( &error ) )
  35. // ShowError( &error );
  36. if ( !steam->StartEngineEx( &error, false, false ) )
  37. ShowError( &error );
  38.  
  39. if ( !steam->Startup( STEAM_USING_ALL, &error ) )
  40. ShowError( &error );
  41.  
  42. const char *userName = "limetech";
  43. const char *passWord = "hurrdurrderp";
  44.  
  45. SteamCallHandle_t handle = steam->Login( userName, passWord, 1, &error );
  46. if ( handle == STEAM_INVALID_CALL_HANDLE )
  47. ShowError( &error );
  48.  
  49. if ( !steam->BlockingCall( handle, 100, &error ) )
  50. ShowError( &error );
  51.  
  52. char szUser[ 255 ];
  53. uint32 userChars;
  54. TSteamGlobalUserID globalId;
  55.  
  56. if ( !steam->GetUser( szUser, sizeof( szUser ), &userChars, &globalId, &error ) )
  57. ShowError( &error );
  58.  
  59. char szEmailAddress[ 255 ];
  60. uint32 emailChars;
  61.  
  62. if ( !steam->GetCurrentEmailAddress( szEmailAddress, sizeof( szEmailAddress ), &emailChars, &error ) )
  63. ShowError( &error );
  64.  
  65. szUser[userChars]='\0';
  66. printf("User: %s\n", szUser);
  67.  
  68. szEmailAddress[emailChars]='\0';
  69. printf("Email address: %s\n", szEmailAddress);
  70.  
  71. printf("Steam2 - Logged on!\n");
  72.  
  73. void* steamclient_library = dlopen("steamclient.so", RTLD_LAZY);
  74. CreateInterfaceFn factory = (CreateInterfaceFn)dlsym(steamclient_library, "CreateInterface");
  75. dlclose(steamclient_library);
  76.  
  77. if ( !factory )
  78. {
  79. std::cout << "Unable to load steamclient factory." << std::endl;
  80. return 0;
  81. }
  82.  
  83. ISteamClient009 *steamClient = (ISteamClient009 *)factory( STEAMCLIENT_INTERFACE_VERSION_009, NULL );
  84. IClientEngine *clientEngine = (IClientEngine *)factory( CLIENTENGINE_INTERFACE_VERSION, NULL );
  85.  
  86. HSteamPipe hPipe;
  87. HSteamUser hUser = clientEngine->CreateGlobalUser( &hPipe );
  88. if ( !hUser || !hPipe )
  89. {
  90. std::cout << "Unable to connect to global user." << std::endl;
  91. return 0;
  92. }
  93.  
  94. IClientUser *clientUser = (IClientUser *)clientEngine->GetIClientUser( hUser, hPipe, CLIENTUSER_INTERFACE_VERSION );
  95. IClientFriends *clientFriends = (IClientFriends *)clientEngine->GetIClientFriends( hUser, hPipe, CLIENTFRIENDS_INTERFACE_VERSION );
  96. ISteam2Bridge002 *steam2Bridge = (ISteam2Bridge002 *)steamClient->GetISteamGenericInterface( hUser, hPipe, STEAM2BRIDGE_INTERFACE_VERSION_002 );
  97.  
  98. CSteamID steamId;
  99. steamId.SetFromSteam2( &globalId, steam2Bridge->GetConnectedUniverse() );
  100.  
  101. clientUser->SetEmail( szEmailAddress );
  102. clientUser->SetLoginInformation( userName, passWord, false );
  103.  
  104. // This starts the thread causeing the crash.
  105. clientUser->LogOn( steamId );
  106.  
  107. ELogonState state = clientUser->GetLogonState();
  108.  
  109. while ( state == k_ELogonStateLoggingOn )
  110. {
  111. state = clientUser->GetLogonState();
  112. }
  113.  
  114. CallbackMsg_t callBack;
  115. while ( true )
  116. {
  117. if ( Steam_BGetCallback( hPipe, &callBack ) )
  118. {
  119. switch (callBack.m_iCallback)
  120. {
  121. case SteamServersConnected_t::k_iCallback:
  122. {
  123. printf("Steam3 - Logged on!\n");
  124.  
  125. clientUser->SetComputerInUse();
  126. clientUser->SetSelfAsPrimaryChatDestination();
  127. clientFriends->SetPersonaState( k_EPersonaStateOnline );
  128. break;
  129. }
  130. }
  131.  
  132. Steam_FreeLastCallback( hPipe );
  133. }
  134.  
  135. sleep(10);
  136. }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement