Author Topic: PLUGIN INTERFACE: AGS2Client - Common interface for Steam, GOG Galaxy, etc.  (Read 2702 times)  Share 

monkey0506

  • AGS Project Tracker Admins
  • Tasting the banhammer. Strangely, tastes like ham.
This may be fairly mundane, but I have created a common interface for client plugins that AGS can use to communicate with clients like Steam and GOG Galaxy. In fact, those are the only two clients I know of presently that offer the whole game-library-with-achievements-and-so-forth type of "client", but it's always possible that others will rise up.

In related news, this does mean that I am working on a GOG Galaxy plugin! Hopefully that should be made available soon. As far as I know, the GOG Galaxy SDK is open source, so that plugin will also be fully open-sourced, unlike AGSteam. The official stub source code for AGSteam will later be updated to this much improved interface as well.

I created a demo project to show how this interface can be used to stub these client plugins rather simply. You can grab the source for that at the link below (the interface itself is a referenced submodule in a separate repo):

https://github.com/monkey0506/ags2client_demo

P.S. Additionally, this common interface should make it relatively simple for AGS devs to implement Steam and Galaxy features in a uniform fashion. That seems like it would be appreciated. ;)

P.S.S. The Visual Studio solution files I provided for the demo are VS 2013 solution files, and the interface does make use of C++11 features. The demo was tested with AGS 3.4.0.5 and gave me no issues.
« Last Edit: 19 Jul 2015, 19:52 by monkey0506 »
User was banned for this post.

Dualnames

  • Local Moderator
  • Rottwheelers
  • Pretty Badass
  • Dualnames worked on a game that was nominated for an AGS Award!Dualnames worked on a game that won an AGS Award!
I may be incredibly dumb right now, but i don't understand what exactly this does.
No more military army stuff. I'm alive and back.

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
I may be incredibly dumb right now, but i don't understand what exactly this does.
If I understand correctly, this is a uniform script header for all possible client plugins released in future.

Write game script 1 time, then just replace client plugin dll in your game (from Steam to GoG and whatnot), and it will work.
« Last Edit: 19 Jul 2015, 20:55 by Crimson Wizard »

monkey0506

  • AGS Project Tracker Admins
  • Tasting the banhammer. Strangely, tastes like ham.
That's the general idea, yes. I don't foresee any need to have the Steam plugin pushed out over GOG Galaxy, for example, so there's a good chance that most of the function calls could be set up in a synonymous way.

The source code for the various client plugins can reference this interface to reduce code duplication. Some minimal defaults are already in-place, so things like registering the script header and the various functions can largely be handled by the AGS2Client interface. New (common) features (if any) could also be implemented at the interface level, and perpetuated to the client plugins by updating the git submodule (as opposed to having to recreate the changes for each plugin).

This probably won't be widely useful to most people. But in theory it allows me to maintain both plugins in a user-friendly and open-source way while supporting closed-source frameworks like Steamworks with relatively little unseen/private code. This also is an effort to make sure that the client plugins may be properly stubbed for platforms that the client doesn't yet support.
User was banned for this post.

monkey0506

  • AGS Project Tracker Admins
  • Tasting the banhammer. Strangely, tastes like ham.
Now that I've finally gotten around to finishing the GOG plugin and updated the Steam plugin, I made a sample project that shows how you can set up your achievement code once in AGS and not have to worry about duplicating the code.

Downloads and such

To set up your game (using the Steam+Galaxy project), there are only a few things that need to be done:

1) Make sure that on the Steam and GOG backend websites, your achievements are set up with exactly the same API names (this is the name you use to set the achievements from AGS).
2) Replace the contents of "steam_appid.txt" in your Compiled folder with your Steam game's app ID. For release builds, you can delete this file entirely, but you don't have to.
3) In the Achievements script header, add your GOG Galaxy client ID and client secret.
4) In the Achievements script header, create friendly enum names for each achievement.
5) In the Achievements script file, set the API name that corresponds to each enum'd achievement.
6) In the Achievements script file, modify or remove the on_key_press function to match your game's needs. Call Achievements.Set as needed (instead of AGS2Client.SetAchievement!) and you will also be able to build with both plugins disabled.
7) Make sure you have the appropriate plugin enabled for the release you want to build (if any), and "Rebuild all files" (trust me, it's for the best when changing plugins).
8) For release, make sure to remove the Steam- or GOG-specific plugins from your Compiled folder.

P.S. I've also recently come across "Galaxy Crossplay". I'm not aware of any AGS games using matchmaking features (yet!), but it would be entirely possible to use both plugins simultaneously and thereby allow setting achievements in Steam to also set the achievement in GOG Galaxy. For this you would need the "non-unified" variant of the plugins. I'll work on cleaning up the project files to make more sense of this, and release appropriately named binaries.
User was banned for this post.

monkey0506

  • AGS Project Tracker Admins
  • Tasting the banhammer. Strangely, tastes like ham.
REGARDING 'UNIFIED' CLIENT PLUGINS

The client plugins I have written (AGSteam and AGSGalaxy) now support "unified" building by default. This means that you will use "AGS2Client" in place of "AGSteam" or "AGSGalaxy" in most cases. A call such as:

Code: Adventure Game Studio
  1. AGSGalaxy.SetAchievementAchieved("NAME");

Will instead become:

Code: Adventure Game Studio
  1. AGS2Client.SetAchievementAchieved("NAME");

(and likewise for AGSteam)

The benefit behind this is that you can toggle between AGSGalaxy and AGSteam (or other future plugins) without having to change your game scripts. To take full advantage of the unified plugin builds, you must ensure that the "API name" (the name you call from your game scripts) is exactly the same on both the Steamworks and GOG Galaxy backend websites. This is what makes the unified build work! Once the achievements are set up properly on the backend websites, you can toggle between using the AGSteam and AGSGalaxy plugin and rebuild your game without having to change any code (or duplicate any code). For an example of this in action, see the Steam+Galaxy project (instructions).

Note that the unified builds replace the client-specific struct name ("AGSteam"/"AGSGalaxy") with "AGS2Client", and so the version macro is replaced with "AGS2Client_VERSION". However, to ensure that client-specific functions can still be utilized, the client-specific version macro is also defined. So the AGSteam unified plugin will define "AGS2Client_VERSION" and "AGSteam_VERSION" both with the version number of the Steam plugin. AGSGalaxy will define "AGS2Client_VERSION" and "AGSGalaxy_VERSION" both with the version number of the GOG Galaxy plugin. This is necessary in particular to initialize the GOG Galaxy plugin, which requires a client ID and client secret not required in initializing the Steam plugin. See the Steam+Galaxy project for an example of how to implement this.

You may instead choose to utilize the "disjoint" build of the plugin, which still uses "AGSteam" or "AGSGalaxy" instead of "AGS2Client", but this means you will have to use separate code for Steam and Galaxy builds. A practical reason why you might want to do this is to allow "Galaxy crossplay" builds. Essentially that means that you would include BOTH the AGSGalaxy AND AGSteam disjoint builds AT THE SAME TIME. You would initialize both client APIs, and call their respective functions separately. Doing so would allow you to have a single build of your game released on Steam and GOG Galaxy. As long as the player has both clients installed, then they can gain achievements for both clients at once. The disjoint plugin builds have "-disjoint" in the filename, but you can rename the binary (DLL) as needed for compatibility with an older game that uses client-specific game scripts.
« Last Edit: 12 Jan 2016, 19:47 by monkey0506 »
User was banned for this post.

Dave Gilbert

  • Mittens Vassal
  • AGS Baker
  • Hi. Our names are FRIGGING ADORABLE.
    • Lifetime Achievement Award Winner
    •  
  • Dave Gilbert worked on a game that was nominated for an AGS Award!Dave Gilbert worked on a game that won an AGS Award!
Sorry to necropost, but is there any documentation for this plugin? E.g., a list of commands that you can use? I searched around the forum but I can't seem to find any anywhere.

Thanks!

monkey0506

  • AGS Project Tracker Admins
  • Tasting the banhammer. Strangely, tastes like ham.
There is now a wiki, which explains using AGS2Client plugins.
User was banned for this post.