Advertisement

Is it possible to have saves that work with and without steam cloud saves?

Started by October 13, 2020 06:00 PM
8 comments, last by Stocke 4 years, 1 month ago

I have a basic save system set up that reads/writes from files. I want to add steamworks support and cloud saves. But I also want to be able to launch the game in itch.io and be able to save.

Is this possible? If so, is this possible in 5he same build or do I have to compile different builds with #ifdef conditions for each platform?

Do keep in mind that I have not yet tried using steamworks so I don't know how saves there work. Can I just tell steam to upload a particular save folder to cloud?

And I suppose this extends to other features that work differently for different platforms. like achievements. What is the best approach with things like this?

You usually have a wrapper library or something that covers different stores and initializes the API if necessary. Otherwise itch.io users would be facing the Steam Login Screen because you never turn it off.

If you have a limited amount of APIs you need to integrate, a simple conditional compilation switch (aka #ifdef) would work, otherwise try to find a wrapper library that initializes the APIs you need

Advertisement

Shaarigan said:

You usually have a wrapper library or something that covers different stores and initializes the API if necessary. Otherwise itch.io users would be facing the Steam Login Screen because you never turn it off.

If you have a limited amount of APIs you need to integrate, a simple conditional compilation switch (aka #ifdef) would work, otherwise try to find a wrapper library that initializes the APIs you need

I'm willing to do write the wrappers since I don't know if there are any that fulfill my criteria and I'm new to releasing on steam.

But for that, I need to know two things:

  1. Is it possible to know through the steam API if the installed version came from steam? Like if some insane person installed both itch and steam version I want things to work separately.
  2. How exactly does the steam cloud save API work? Can I just tell it what folder/files to upload?

Are those two things possible?

Stocke said:
Is it possible to know through the steam API if the installed version came from steam? Like if some insane person installed both itch and steam version I want things to work separately.

No it isnt. Either you have the Steam API activated or you don't. Steam API always tries to connect to Steam if it is initialized

Stocke said:
How exactly does the steam cloud save API work? Can I just tell it what folder/files to upload?

I worked with cloud save once in a while but as far as I remember, you don't specify a folder or file rather than data to be uploaded to it. So a Steam driven savegame is written by the Steam API either to disk or cloud save or both if the user made the settings to either of. But the breaking point is that it will decide that in the API itself, not your code.

Same for if you try to install the same game from Steam and GOG, as long as they stay apart, everything is fine and every build is using it's own store API

@Shaarigan

Shaarigan said:

Stocke said:
Is it possible to know through the steam API if the installed version came from steam? Like if some insane person installed both itch and steam version I want things to work separately.

No it isnt. Either you have the Steam API activated or you don't. Steam API always tries to connect to Steam if it is initialized.

Does steam initialize the API automatically when steam launches the game? In which case, would launching from the exe not initialize it?
If I'm responsible for calling initialize, then the easiest way seems to be #Ifdefs for other platforms that don't want that.

The simplest (and arguably cleanest) way to handle this is separate executables. No Steam-specific code in the itch.io executable at all. No itch.io-specific code in the Steam executable either. The more different distribution channels you have, the more this makes sense. If you have 10 different distribution channels, each with their own dlls, you probably don't want to distribute all 10 dlls with your game!

If for some reason you only want a single executable, you need some marker outside of your executable to tell it which behavior it should use. The simplest way is to simply check for the existence of a file in the game's main directory. Put a file called “steam_build” in your game directory for the Steam version, but not the itch.io version. If a file called “steam_build” exists in that directory, use the Steam behavior.

The clever way to have a single executable is to use the steam dll file itself for this check. If there is a file called “steam_api64.dll” in your game directory, load it and use the Steam behavior. If there isn't, fall back to the default (itch.io) behavior. However, this requires that you use explicit runtime linking (LoadLibrary/GetProcAddress on Windows) instead of DLL imports, which may be more hassle than it's worth.

Advertisement

Stocke said:
Does steam initialize the API automatically when steam launches the game? In which case, would launching from the exe not initialize it?

A quote from the docs

After you have the Steamworks API set up within your project you can start using it by calling SteamAPI_Init function to initialize the API. This will set up the global state and populate the interface pointers which are accessible via the global functions which match the name of the interface. This MUST be called and return successfully prior to accessing any of the Steamworks Interfaces!

so you have to initialize it manually with the propper AppID

a light breeze said:
If there is a file called “steam_api64.dll” in your game directory, load it and use the Steam behavior. If there isn't, fall back to the default (itch.io) behavior

Assume OP wants to sell the game on Steam and/or itch.io, this a dangerous approach. One could just delete the Steam API from the folder and the game runs without DRM checks

Agreed that it is critical, but security is only a minor reason. How you distribute your products and what libraries you will depend on – ESPECIALLY huge blocks of functionality like SteamAPI implements – are major business decisions. Choosing to target Steam, or Lumberyard, or use GameSpy, or use middleware or any third-party tools, each decision affects time and effort.

Building good abstractions let you save data anywhere, including on multiple cloud services, but comes with the cost of implementing it.

@Shaarigan Those are good points. I completely forgot about DRM. Thank you for your answers. I'll dive into steam's API this weekend.

This topic is closed to new replies.

Advertisement