Home

Awesome

Steamworks.Net MonoGame Integration

This repo is for everyone who is about to integrate the Steamworks.Net.dll into a MonoGame project. It shows some Steamworks.Net features and how easy it is to integrate it into a MonoGame project.

HelloSteamworks HelloSteamworks

Building

The following is required to successfully compile the solution:

How To

To set up your own MonoGame with Steamworks.Net integration project you need to do the following steps:

using Steamworks;

protected override void Initialize()
{
    try
    {
        if (!SteamAPI.Init()) Console.WriteLine("SteamAPI.Init() failed!");
        else isSteamRunning = true;
    }
    catch (DllNotFoundException e)
    {
        Console.WriteLine(e);
    }
}
protected override void Update(GameTime gameTime)
{
    if (isSteamRunning == true) SteamAPI.RunCallbacks();

    base.Update(gameTime);
}
private void Game1_Exiting(object sender, EventArgs e)
{
    SteamAPI.Shutdown();
}

Add the EventHandler Exiting += Game1_Exiting and then the SteamAPI.Shutdown() method.

You should be able to build and run the project now. It may be possible that you will receive the following exception:

An unhandled exception of type 'System.BadImageFormatException' occurred in SWTEST.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.

In this case you need to make sure, that you took the right assemblies for your target platform. E.g. When you took the assemblies from the repo directory "Steamworks.Net-MonoGame-Integration/Steamworks.NET/Windows-x86/", then you need to configure your project to build it for the x86 platform. Use the integrated configuration manager to create or choose the right platform. It will look like this:

You should also define the right "conditional compilation symbols":

Type in "WINDOWS", when building for the windows platform and "LINUX", when building for linux.

Latest now it should build without an exception.

Samples

Note: You need to start your steam client before executing the examples. Otherwise you won't receive any data -obviously ;)

Have fun!