Facepunch.Steamworks + MonoGame.Framework = the easiest SteamAPI Integration for your app!
OTHER License
Facepunch.Steamworks + MonoGame.Framework = the easiest SteamAPI Integration for your app!
The following is required to successfully compile the solution:
To set up your own MonoGame with Facepunch.Steamworks integration project you need to do the following steps:
Add the Facepunch.Steamworks.dll per NuGet or the included modified source
Add steam_api64.dll as a link to your project and set "copy to output directory" to "copy if newer"
Add steam_appid.txt this step is not needed anymore!
Initialize the API with the method SteamClient.Init(); like this:
using Steamworks;
protected override void Initialize()
{
try
{
SteamClient.Init(480);
IsSteamRunning = true;
SteamUtils.OverlayNotificationPosition = NotificationPosition.BottomRight;
}
catch (Exception e)
{
Console.Out.WriteLine(e.ToString());
}
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
if (IsSteamRunning) SteamClient.RunCallbacks();
}
private void Game1_Exiting(object sender, EventArgs e)
{
if (IsSteamRunning) SteamClient.Shutdown();
}
Add the EventHandler Exiting += Game1_Exiting and then the SteamClient.Shutdown() method.
The greatest thing about Facepunch.Steamworks is, that you can write code in native C#! Say bye bye to manual function calling and finally code like this again:
foreach ( var friend in SteamFriends.GetFriends() )
{
Console.WriteLine( "{friend.Id}: {friend.Name}" );
Console.WriteLine( "{friend.IsOnline} / {friend.SteamLevel}" );
friend.SendMessage( "Hello Friend" );
}
public static async Task<Texture2D> GetUserImage(SteamId id, GraphicsDevice device)
{
var image = await SteamFriends.GetMediumAvatarAsync(id);
if (image.HasValue)
{
Texture2D avatarTexture = new Texture2D(device, (int)image.Value.Width, (int)image.Value.Height, false, SurfaceFormat.Color);
avatarTexture.SetData(image.Value.Data, 0, image.Value.Data.Length);
return avatarTexture;
}
else return null;
}
UserAvatar = GetUserImage(UserID, GraphicsDevice).Result;
More samples here: https://github.com/Facepunch/Facepunch.Steamworks
Note: You need to start your steam client before executing the examples. Otherwise you won't receive any data -obviously ;)
Have fun!