2

I want to use Steam DRM integrated in the SteamWorks-API to protect a game implemented in C# using XNA (or Monogame/FNA for Mac and Linux). Valve itself only provides its SteamWorks-API in C++, but there are wrappers like SteamWorks.Net für C#. However, as far as I know, these only support major features (like cloud save and achievements) but that do not support Steam DRM.

Is there any way to integrate Steam DRM with a C# game?

If no, what are alternatives?

ares_games
  • 1,019
  • 2
  • 15
  • 32

2 Answers2

3

OP:

Is there any way to integrate Steam DRM with a C# game?

Directly? No. Indirectly? Yes. Let me explain...

What you really want to know is how can c# code call c++ and the answer is yes. Tell me more. If you look at the link, the best answer is to modify the c++ code to change it to a hybrid c++/CLI DLL. Since that's not possible with the Steam provided API, the alternative is to create a proxy.

The thing to do (since you can't modify the c++ DLL) is create a new c++/CLI DLL (let's call it Proxy) that calls the Steam C++ DLL (S) on your behalf. This gets around the problem of p-invoking a c++ DLL which is subject to name mangling as opposed to a c DLL which does not. Proxy exposes classes that are a mix of c++ and .NET. Your app calls what it thinks is just .NET code inside the proxy. Proxy then calls the raw c++ code in S.

Call sequence goes like this:

App --> Proxy --> S

If you notice you will learn that the proxy is really just your own wrapper - a very simple one for the specific functions your app is interested in, so again the reliance for a 3rd party wrapper does not seem worth it considering the risk. There should not be any special and/or complex business logic in your proxy. Keep it simple. Be sure to keep your copy of the steam code/libs up to date with Steam's latest API.

OP:

but there are wrappers like SteamWorks.Net für C#. However, as far as I know, these only support major features (like cloud save and achievements) but that do not support Steam DRM

Personally I wouldn't want to rely on a potentially unproven; subject to becoming out of sync with Steam changes; 3rd party open source project for something as important as DRM so my advice is stick with SteamWorks proper.

What's c++/CLI?

Briefly, c++/CLI is a Microsoft technology that has been around for some time now that allows you to create a hybrid c++ and .NET DLL. Your code has access to .NET as well as the wealth of historic c/c++ code and libs. .NET code can call public CLR types in the hybrid dll.

More

  • name mangling - a somewhat annoying aspect of c++ compilers that turn method names like bool article::print_to (std::ostream&) into _ZN9wikipedia7article8print_toERSo for many reasons, one of which is for the need of unique naming, but have the unwanted side effect of making it difficult to determine which export is the entry to p-invoke.
Community
  • 1
  • 1
  • 1
    @Aravol Yes, I assume that is the one inferred by the OP in _"SteamWorks.Net für C#"_. Again, I think it's overkill to have a _whole_ .NET wrapper for _SteamWorks_ (matchmaking; DLC; voice chat etc) when the OP is just after DRM aspects and even then making your own wrapper/proxy is pretty easy. There is minimal code in the proxy. :) –  Jan 24 '16 at 02:33
  • Thanks for the great idea how to use SteamWorks.dll (directly from Valve) I will definetely try to do this. However, I think the SteamWorks DRM wraps to executable which is still C# even if one uses the suggested C++/CLI proxy dll. – ares_games Jan 24 '16 at 02:40
  • Furthermore, in the SteamWorks.net FAQ they state: Question: "Does the Steam DRM wrapper work with Unity or XNA/Monogame?" Answer "No it doesn’t. Unfortunately the Steam DRM wrapper does not play well with .NET applications such as Unity and your application will likely fail to start if it’s wrapped. Even if it does succeed and work for you it will often fail on other computers." https://steamworks.github.io/faq/ – ares_games Jan 24 '16 at 02:40
  • That's interesting about Steam DRM and .NET. Steam itself says _"[Do you have a .NET or Actionscript wrapper?...We do not have any wrappers available as part of the SDK.](https://www.steampowered.com/steamworks/FAQ.php)"_ and then they say _"[Do you have a DRM solution for .NET...We currently do not have a way to DRM these titles](https://www.steampowered.com/steamworks/FAQ.php)"_ but it's unclear if that means they don't support .NET processes entirely or if they just don't have .NET support in the SDK. There are XNA games on Steam afterall (unable to confirm DRM). Don't know... –  Jan 24 '16 at 04:14
1

According to Steamworks.NET

Does the Steam DRM wrapper work with Unity or XNA/Monogame?

No it doesn’t. Unfortunately the Steam DRM wrapper does not play well with .NET applications such as Unity and your application will likely fail to start if it’s wrapped. Even if it does succeed and work for you it will often fail on other computers.

So at least one major implementation has found this exact aspect untenable.

Note that there are multiple steam games which use third-party licensing software, and instead of being integrated to steam will display a product key on startup. This may help open up your options.

David
  • 10,458
  • 1
  • 28
  • 40