Skip to content

Steam Integration

Regular Standalone File Activation opens up your game when someone clicks on a file you registered as the default handler. But if your game is on Steam you are probably using its SDK or DRM capabilities to further enhance your players' experience.

If you open a Steam game from its installation folder, since it wasn't open via steam it probably won't be able to communicate with valve software in order to report achievements, stats, etc, or it won't simply launch due to the DRM feature.

So using the regular File Activation mechanism where we associate a file type to a game executable wouldn't work since the game would possibly lose functionality or simply wouldn't start.

To avoid this issue, instead of registering your game to your desired file type, we configure the target systems to open steam instead of your game, but we parameterize Steam to open your game as soon as it's initialized.

Configuring Steam Integration

To enable the Steam capability of ImaginationOverflow File Association Plugin you first need to have a valid app id, for that you need to get access to Steam Direct. After that valve will attribute to your game an ID.

szvid.png

As an example, Sudoku Zenkai id is 809850.

Then you need to configure the plugin with this id:

steamint.png

The final step of the configuration to enable the Steam integration is setting the IsSteamBuild Property under FileAssociationManager:

ImaginationOverflow.UniversalFileAssociation.FileAssociationManager.Instance.IsSteamBuild = true;

If your game is on Steam there is a good chance that you offer DRM-free versions of it on other stores, so don't forget to turn off this option when making DRM-free standalone builds, a good way to do this automatically is using compilation flags.

#if STEAM_BUILD
ImaginationOverflow.UniversalFileAssociation.FileAssociationManager.Instance.IsSteamBuild = true;
#else
ImaginationOverflow.UniversalFileAssociation.FileAssociationManager.Instance.IsSteamBuild = false;
#endif

Mac and Steam Integration

Mac File Association works a little different from the Windows and Linux, you have to take special care when integrating the plugin with Mac and Steam. On Linux and Windows, the plugin handles the registration of the File Types when the game is first open. This enables the plugin to register whatever it wants on these platforms. On Mac, the file activation feature is fully controlled by the OS and the plugin can't change the default configuration, which opens your game directly.

The OS itself doesn't know that is running a Steam game, so when the user clicks on a configured file type, the OS opens the game executable. This means that you need to explicitly delay the enforcement of the DRM until you know if the game was activated via file association or not.

The plugin is configured in a way that when it's running a Steam game on MacOS it will always fire the FileActivated event even if the game wasn't activated via file activation. This way is possible to store the file info before enforcing any DRM in the game.

Solution Suggestion

Below is the code that we use on Sudoku Zenkai to handle this tricky issue, for Steam integration we are using Steamworks.NET.

The user flow for this situation is the following:

  1. User clicks on a file type.
  2. The game opens
  3. The game enforces DRM and launches the game on Steam.
  4. Steam launches (if not already running).
  5. Steam launches the game.

To ensure that we process the file that the user initially clicked we need to save it before enforcing the DRM, in the code below we do exactly that:

  1. The game is activated via file activation.
  2. The FileActivated event is triggered.
  3. Save the file information (since it's impossible to have the game launch on steam via file activation)
  4. Check if the game has steam access, if not restart.
  5. If we are already on steam, load the previously saved activation
  6. Resume file activation.

This behavior is only possible because the plugin always triggers the FileActivated event (on Steam Mac builds) regardless if it was activated via a file activation or not.

    public void RegisterForActivation()
    {
#if UNITY_STANDALONE_OSX && STEAM_BUILD
        FileAssociationManager.Instance.FileActivated += SteamOsxActivation;
#else
        FileAssociationManager.Instance.FileActivated += Instance_FileActivated;
#endif
    }

    private void SteamOsxActivation(FileInformation s)
    {
        //
        //  On Steam OSX builds the plugin triggers the FileActivated with the  
        //  file information or with a null Path if it wasn't activated 
        //  via a file
        //
        if (string.IsNullOrEmpty(s.Path) == false)
            YourGameStorage.SaveFileActivation(s);

        //
        //  Enforce DRM
        //
        if (Steamworks.SteamAPI.RestartAppIfNecessary(new Steamworks.AppId_t([YourAppId])))
        {
            Application.Quit();
            return;
        }

        //
        //  We are already running on Steam, so load any saved file activations
        //
        s = YourGameStorage.LoadSavedFileActiation();

        if (s == null)
            return;

        //
        //  Clear the activation ensuring that the game won't be activated again 
        //  with the same file, this will depend on your storage infrastructure.
        //  
        YourGameStorage.ClearActivation();

        //
        //  Process file activation
        //
        Instance_FileActivated(s);
    }

This behavior only happens when the game is running on Mac and you set the Steam flag to true, on the other combinations the plugin only fires the FileActivated event in case of an actual activation.