📜 ⬆️ ⬇️

We work with SteamWorks. Part 1

SteamWorks is an interface that provides development and publishing tools for game developers. It provides integration with the Steam client, integration with the community, add and edit achievements for games and much more.

At the moment, access to SteamWorks can be obtained if you are a “game studio” and want to distribute your application in steam or through the Steam Greenlight service, thereby becoming a partner of steam. Details here . Open SteamWorks is an open source implementation of Steam api (a disassembled version of steam libraries.)

“Open SteamWorks designed for people who know what they do” - Ryan Stecker. So the author of the open version answered the question (not mine) about the availability of additional documentation, all the documentation that is available is comments in the source code . Download the latest version of Open SteamWorks from the site .

I will use Visual Studio, if you have a mingw on hand, you can use it. Let's start creating a console application (you can use the sample test platform from open steamworks).
We connect the necessary header files.
')
#include <SteamclientAPI.h> #include <SteamAPI.h> 

We connect the necessary libraries to compile our application.

 #pragma comment( lib, "../Resources/Libs/Win32/steamclient" ) #pragma comment( lib, "../Resources/Libs/Win32/steam" ) 

We get the base Steam with 12 version of the interface.
In a disassembled form, this is compiled as a search in the registry for the path to the stim and connection to it.

 CSteamAPILoader loader; auto *Client = (ISteamClient012 *)loader.GetSteam3Factory()(STEAMCLIENT_INTERFACE_VERSION_012, NULL); 

Check if we could get the base.

 if ( !Client ) { printf("Unable to get ISteamClient."); } 

Create a pipe for interaction.

 HSteamPipe pipe = Client->CreateSteamPipe(); 

Checking the pipe.

 if ( !pipe ) { printf("Unable to get pipe"); } 

Connect to the global user (running Steam).

 HSteamUser user = Client->ConnectToGlobalUser( pipe ); 

Verify connectivity to the global user.

 if ( !user ) { printf("Unable connect to global user"); } 


We get access to api v 12 user interface.

 auto *User = (ISteamUser012 *)Client->GetISteamUser( user, pipe, STEAMUSER_INTERFACE_VERSION_012); 

We get access to api v.13 and v. 1 interface friends.

 auto *Friends = (ISteamFriends001 *)Client->GetISteamFriends(user, pipe, STEAMFRIENDS_INTERFACE_VERSION_001); auto *Friends13 = (ISteamFriends013 *)Client->GetISteamFriends(user, pipe, STEAMFRIENDS_INTERFACE_VERSION_013); 

I warn those who will use IClient interfaces (IClientUtils, IClientFriends, etc.), all these interfaces stop working immediately after the global update steam, your application will generate errors, use ISteam (stable) described above, if you really need to use functions from IClient interfaces, and this sometimes happens, copy all the important DLL files for your application (you can see in the import table) and keep it in the folder with your application.

Now we will try to do the simplest thing, change the status of the incentive. (api for changing status is available in the first version of the interface)

 Friends->SetPersonaState(k_EPersonaStateSnooze); 

We compile, run and now we have the status of sleeping in the incentive.

We get the number of friends.

 int friendcount = Friends->GetFriendCount(); printf("%d",friendcount); 


Change your name

 Friends->SetPersonaName("Big_balls"); 


We iterate over our friends, get the SteamID structure (64bits) of the current friend by index, check the status of the current friend, if it is equal to the online status and the name of the friend Crey, send him a message.

 for(int i = 1; i < friendcount + 1; i++) { CSteamID thisfriend = Friends->GetFriendByIndex(i); if(Friends->GetFriendPersonaState(thisfriend) == k_EPersonaStateOnline && strstr(Friends- >GetFriendPersonaName(thisfriend),"Crey") != 0) { char myMsg[] = "My friend Crey is online."; Friends->SendMsgToFriend(thisfriend, k_EChatEntryTypeEmote,myMsg,strlen(myMsg)+1); } 


I think everyone now understands that with the help of SteamWorks you can easily write a trade bot, to exchange things at a “set rate” and a lot of interesting things.

In the following parts we will look at working with IScreenshots, IUserstats (achievements), callbacks, and perhaps it comes to writing a bot.

Source: https://habr.com/ru/post/157999/


All Articles