Tutorials / Guides on how to use Steamworks.NET ?

Hello guys.

I’m working on a game that uses MonoGame and is coming to Steam at some point, and I’m looking now how to make Achievements, Steam Cloud and other stuff.
Steamworks.NET seems way to go for this, but I can’t seem to find any guides on how to use Steamworks.NET with MonoGame.

Have you guys used Steamworks.NET, or are there tutorials on how to setup and use it?

Thanks for reading.

  • DedruPooru

Hi, welcome to the forums,

There is a related post here:

1 Like

Thanks for the answer, I saw that post earlier but it is “What to Use” and not “How to use”.

The second line says:

Steamworks.NET was designed to be as close as possible to the original C++ API, as such the documentation provided from Valve largely covers usage of Steamworks.NET. Niceties and C# Idioms can be easily implemented on top of Steamworks.NET.

and there is a link to documentation from that repo too.

Hey DedruPooru and other people who are struggeling with the integration of Steamworks.Net into a MonoGame project!

Fortunately it’s very easy to integrate Steamworks.Net into a MonoGame project.
Unfortunately I don’t have time to write a detailed tutorial but I created a repo on GitHub with a small description on how to integrate the Steamworks.Net dlls into a MonoGame project.

Feel free to check it out here:

I hope this helps you and other people in the future.

Cheers,
-Marcel

1 Like

Such a nice repo.
Thank you very much…

I’m currently working on a solution that lets you swap Steamworks with Lidgren on demand, since you don’t know if your game makes Steam-Greenlight when you start it and maybe you’d want to sell it on other platforms as well and you’d like your players to be able to play with each other cross-platform…
But I’m afraid it’s only in the drafting-phase.
Maybe you find some time to check it out…

1 Like

Hey throbax and thanks for your compliment!

I like your idea of easy swapping the network environment and I’m curious about the further development. Would be cool to have something handy and easy to use :slight_smile:

Oh and just in case you missed the news: Valve is also swapping his service Steam Greenlight this spring ('17) with their new service called “Steam Direct”.
Read this: http://steamcommunity.com/games/593110/announcements/detail/558846854614253751 to know more about it. I don’t want to be off-topic, just a quick note for you.

Again thanks and good luck with your interesting project!

Thx sqrMin1 for the linked article… I’ve read that before and, frankly, I don’t think that it will work out.
They will charge a fee, ok. They don’t tell how much it will be, not so ok.
But I think that regardless of the fee the amount of rubbish that will get published there will increase and the community will react on that…
I’m interested in how that will unfold.

Nevertheless developers will still want to use the Steam-servers or not, or they will want to enable players without access to steam-servers to play the game.
So nothing will change for the planned library…

But at the current amount of spare-time I’ve left to spend on that project it will likely take me forever anyways. :slight_smile:

I’ll second the need for a Steamworks.NET tutorial as applied to XNA/Monogame. The Steam and .NET documentation leave a lot to be desired while all of the engine folk have easy buttons to make this stuff happen more or less automatically. A list of steamworks.NET methods, what they do, and how they work would be helpful.

Just setting things up has a lot of pitfalls. Here’s what I had to do to get things working:

  1. Download the Standalone and Source Code zips from https://github.com/rlabrecque/Steamworks.NET/releases

  2. The Standalone zip will have a Windows x86 folder. In Visual Studio reference the Steamworks.NET.dll in this folder to your main project (the versions in the other folders are 64 bit and will break things). Build.

  3. Add the following to the folder containing your game’s .exe (either debug or release if testing, or what you are actually shipping)
    a) Add the steam_appid.txt file and change the contents to your game’s Steam ID
    b) For XNA or Monogame Windows add from the Standalone Windows x86 folder: Steam_api.dll and CSteamworks.dll (again, don’t take the 64 bit version of Steam_api.dll - it will break things).
    c) For Linux add libsteam_api.so and libCSteamworks.so from the OSX-Linux x64 folder.
    d) For Mac add the CSteamworks.bundle folder from the OSX-Linux x64 folder. Remember the other Source Code .zip that was originally downloaded? Open that up and add Steamworks.NET.dll.config from the Standalone folder.

The above setup works for Windows 32 and 64, Mac 64, and Linux 64. I’m not sure what will happen with Linux 32 bit.

The game should now phone home to Steam automatically, but it is important to test.

  1. Add “using Steamworks” to any relevant classes.

  2. Set up a global bool isSteamRunning so we can ignore steam stuff if the client isn’t running.

  3. In the game’s Initialize(), check if the client is running with “if (SteamAPI.Init())” and if so set your isSteamRunning to true.

  4. Prior to the game’s shutdown, add “SteamAPI.Shutdown();”.

  5. Tie a funny picture or text to isSteamRunning and run the game. If your funny picture shows up, then your game is tied into Steam.

My only implementation was to have the game push achievements to Steam. Most of these worker bee steamworks methods will crash the game if steam isn’t running so be sure to check isSteamRunning each time. It wouldn’t hurt to also put these in a try catch for an edge case where the steam client closes while the game continues. Here’s all you need for pushing achievements to Steam:

  1. “SteamUserStats.SetAchievement(“ID_of_achievement”);”. The ID is the first column/name that you set in Steam. This line immediately pushes the achievement to steam and it will immediately be reflected in the client. For some reason it will delay the achievement time stamp and pop up (icon in corner of screen) until the game is closed. The fix is to follow with:

  2. “SteamUserStats.StoreStats();”. This will immediately time stamp the achievement and immediately create the screen corner pop up.

While testing, you’ll want to use “SteamUserStats.ClearAchievement(“ID_of_achievement”);” This clears the achievement flag for your account so that you can retest. Make sure to comment out or delete before shipping.

Please take a look at this repo:

We are trying to update it with meaningful additions and samples.

There are also Unity examples available were you may want to take a look to adapt Steamworks.Net features:
https://github.com/rlabrecque/Steamworks.NET-Example

I finally got around to implementing Steam, but I can’t even get it running before I run into problems…

The examples run just fine. I even made empty project and added only the necessary lines and DLLs but it still crashes.

I have tried both stable MonoGame 3.6 and latest Development Build for Visual Studio.

An unhandled exception of type 'System.BadImageFormatException' occurred in Test.exe

Additional information: Could not load file or assembly 'Steamworks.NET, Version=9.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.

If the examples run fine, then you need to check in your test project if you add and reference the right assemblies.

I assume you are on windows:

  1. Please try to take the assemblies from the folder “Windows-x86”, which you can find here and add them as new files to your project root.
  2. Choose “copy if newer” in the “copy to output directory”-field.
  3. Finally you need to add the “Steamworks.NET.dll” as a reference in your test project and change the number in the “steam_appid.txt” to the steam app id of your game / software.
  4. Please check in the “Build” tab of your “Properties” if the “Conditional compilation symbols” shows “WINDOWS”. If not you need to type it in.
  5. Build the project and run it.

Please reply if this helped you.

1 Like

The only thing that (I think) was missing was the “WINDOWS” in Conditional compilation symbols. It was LINUX so I changed it to WINDOWS.
…but it didn’t help.

Still, thanks for helping me.
If you have time, here’s my test project that keeps crashing: https://files.fm/u/xuzavw7m

Your solution doesn’t work for me too. And it can’t, because your platform configurations are wrong.

The dll’s in the directory “Windows-x86” are made for x86 platforms but your platform configuration was set to AnyCPU in debug and release mode.

Do this and then your solution will work:

Add these lines to your project.sln file (rightclick and open with editor)

Change these lines in your .csproj file (rightclick and open with editor)

After that you can change your platform configuration in the configuration manager from within your project:

I’m sorry that this is unclear in my repo description. As soon as I have time, I will add this information to the readme.md file.

Now it should work for you. If not or if you need further help, then please reply. Would be also nice if you reply when this solution worked for you.

PS: the last screenshot is in german, but I think you will understand what you should do :wink:
PPS: don’t forget to add the “WINDOWS” constant to your Release configuration as you did for your Debug configuration before, like you statet in your last post.

2 Likes

It works!
Thank you very much :slight_smile:

I added x86 platform via Visual Studio’s Configuration Manager instead of manually editing the files.
Now I just have to start implementing this to the Main Project…

Great. I’m glad I could help :slight_smile:

Just wanted to notify that I extended the “Readme.md”-file with further exception handling advices.

I also did a small bug fix and removed old unnecessary comments.

2 Likes

I recently updated the repo with a new sample project: AchievementHunter!

It’s a simple sample (game) which shows you the correct way of implementing achievements and stats as well as storing them on the steam server. It’s based upon the Steamworks Example ‘SpaceWar’ included with the Steamworks SDK.

You shouldn’t implement just the bare basic of achievement unlocking and storing without error handling and checking if you received the correct data from the steam servers before. Because it’s also possible that you receive achievement and stats data from a different game on steam, which leads to incorrect data and in the worst case it leads to game crashes.

That’s why I created this sample project; to show you how to do achievement unlocking, stats updating and storing everything on the steam server without errors or crashes.

Repo link:

Happy Easter everyone!

@DedruPooru @MobileChicane00 @throbax

3 Likes

Hello @SandboxBlizz,

thanks for the nice work! This project really helps to get me started with Steamworks. However, I am currently not able to start to the Steam overlay in the HelloSteamWorks.Net project. Any suggestions?

Best,
Max

Hey @mgulde,

nice to hear that it already helped you.

What exactly do you mean? Do you mean that you can’t just open the steam overlay or are you having problems to call the steam overlay programmatically?