GoG SDK

Good news: My game is slated to be available on GOG.com.
Bad news: The agreement requires matching Steam functionality - which for me means the achievements I implemented using steamworks.

I’ve had a look at the GOG SDK and I suppose it looks quite similar to Steam’s, technically. I then had a look at @britzl’s steamworks extension to see what is needed and… Oh man. I don’t even know where to begin.

Has anyone else implemented the GOG SDK in a Defold project? Anyone thinking of doing it?

I’m happy to put work in but I’m completely lost. Is anyone in a position to help somehow? :disappointed_relieved:

5 Likes

I think most of the steamworks extension is auto generated from the xml (json?) files that Steam provides.
@britzl has made several scripts to parse and implement this. Perhaps it’s doable to use a similar approach to GOG’s sdk?

2 Likes

That would be great!

I asked GOG for any support from their end and they weren’t forthcoming with help for Defold specifically. All I have are a C++ demo app, a UE4 plugin and a Unity/C# example. These might be useful, but I have looked through them and I still don’t really know where to begin.

Ask them if they (CD PROJEKT) would consider to sponsor an extension for their platform for Defold?

I brought that up but no dice I’m afraid.

I looked through their site and wasn’t able to find anything about an SDK. I did find https://devportal.gog.com/welcome but not sure how to get an account. I sent a support request asking for access.

I’m not very hopeful that it’s possible to generate code to use the SDK. I get the feeling that they do a lot of stuff a bit ad-hoc and quick and dirty.

So it’s achievements and authentication that should be the focus of the GOG SDK implementation then?

1 Like

Yeah, that’s where the information is held.

Yes, that is the use case for me in this specific instance. There is a whole bunch of other functionality (kind of like steamworks) but nothing I need personally at this time.

The sdk is a bunch of “.h” header files written in, well, something that isn’t lua. The gist of the issue is that I don’t understand how to call functions in these files. I’ve spent the past few hours reading up on the native extensions manual and having been able to reproduce the “simple example extension” (:partying_face:) I at least understand that a native extension is what is required to make this work.

I know exactly which methods I need (I’ve included the instructions I’ve received below) and I’m sure with that plus the API documentation I’d manage. It’s “just” finding the way to call these things from my lua scripts that is the issue. I thought (perhaps naively) that as long as I could figure out how to make a native extension work it would simply be a case of referencing the relevant parts in the sdk, but it seems way more complicated than that (particularly after comparing to steamworks.cpp in the steamworks-defold extension :scream:).

I don’t want to come across as lazy, I’m just a bit out of my depth here!

  • Register AuthListener,
  • Log in the user using SignInGalaxy method,
  • Register UserStatsAndAchievementsListener and StatsAndAchievementsStoreListener,
  • Request users stats and achievements data using RequestUserStatsAndAchievements method and wait for the callback on UserStatsAndAchievementsListener (don’t worry, this does not require Internet connection to work),
  • Then to unlock achievement:
  • Use the SetAchievement method,
  • And persist the changes using StoreStatsAndAchievements method,
  • When closing the game make sure to dispose the listeners and use the Shutdown method.
2 Likes

I would recommend that you start here:

  • The basics of native extensions complete with an example: https://defold.com/manuals/extensions/
  • Next I would suggest that you start a new project from the Native Extension template available from the editor Welcome screen. It is the same project as is referenced in the manual above.
  • Add the GOG library files to the extension (in the lib folder), add the header files to the include folder.
  • Start modifying the template project to call the functions defined in the GOG SDK header files.

That is generated code and a very big and complex API that is completely defined in an API definition, including all data structures, responses etc. Don’t take this as the benchmark for native extension complexity!

2 Likes

Is there any guidance on how to do this? I’ve got the library files and header files in the right locations based on your instructions.

I’ve tried modifying this section in the example as follows:

// Functions exposed to Lua
static const luaL_reg Module_methods[] =
{
    {"reverse", Reverse},
    {"signInGalaxy", SignInGalaxy},
    {0, 0}
};

But I get an error:

/myextension/src/myextension.cpp
	Line 41: use of undeclared identifier 'SignInGalaxy'
    {"signInGalaxy", SignInGalaxy},
                     ^

I note that Reverse from the example is defined in the cpp file itself, but that the SignInGalaxy method I am trying to reach is in a header file. Presumably something needs to be done to refer to the appropriate header file, but I don’t know how.

Any hints?

Have you done something like `#include <gog.h>´ (or whatever the filename is?)

1 Like

I did, but had it in quotations instead of < >. I think that was wrong because when I changed it, I was getting messages about other files that needed to be included. Worked through including all of those now. Thanks for the suggestion.

The error message is expanded a bit now:

/myextension/src/myextension.cpp
	Line 7: In file included from upload/myextension/src/myextension.cpp:7:
In file included from /var/extender/sdk/4ebe7a1d548eae2398717ed46f9d7d1b103d5503/defoldsdk//include/dmsdk/sdk.h:23:
In file included from /var/extender/sdk/4ebe7a1d548eae2398717ed46f9d7d1b103d5503/defoldsdk//include/dmsdk/vectormath/cpp/vectormath_aos.h:40:
private field 'd' is not used [-Wunused-private-field]
    float d;
          ^

/myextension/src/myextension.cpp
	Line 7: private field 'd' is not used [-Wunused-private-field]
    float d;
          ^

/myextension/src/myextension.cpp
	Line 59: use of undeclared identifier 'SignInGalaxy'
    {"signInGalaxy", SignInGalaxy},
                     ^

I imagine something in the GOG sdk is clashing with the Defold sdk, because line 7 in the myextension.cpp file is:

include <dmsdk/sdk.h>

The method I am trying to get a hold of looks like this:

virtual void SignInGalaxy(bool requireOnline = false, IAuthListener* const listener = NULL) = 0;

For each API function you wish to call in an SDK there needs to be a “glue” function in the extension.cpp file. The “glue” function read any arguments coming from the Lua script, calls the API function with the arguments, reads any return values and passes those back to the Lua script.

In the case of the SignInGalaxy function it seems to take two arguments: 1) requireOnline and 2) listener. This means that your “glue” function must read one boolean and one function. Something like this:

// store extension state in a struct
struct GOG
{
	// constructor
	GOG()
	{
		memset(this, 0, sizeof(*this));
	}

	dmScript::LuaCallbackInfo*  m_SignInListener;
} g_GOG;


static int GOG_SignInGalaxy(lua_State* L) {
	int top = lua_gettop(L);

	// read first argument, the requireOnline boolean
	const bool requireOnline = (bool)luaL_checknumber(L, 1);

	// read the second argument, the Lua listener function to call when logged in
	// destroy any existing listener first
	if (g_GOG.m_SignInListener) {
		dmScript::DestroyCallback(g_GOG.m_SignInListener);
	}
	g_GOG.m_SignInListener = dmScript::CreateCallback(L, 2);
	...

You also need an instance of the IAuthListener and pass that to the SignInGalaxy() API function. The IAuthListener interface probably defines one or more callbacks with sign in result. In the implementation of these callbacks you read any result data and then call the m_SignInListener.

Also the virtual void SignInGalaxy() is a member function of a class. You need an instance of that class to call it:

gog = // some global function to create a gog context
gog->SignInGalaxy(requireOnline, my_iauth_listerner);

I noticed that Interrogation is on GoG as well: https://twitter.com/InterrogationG/status/1265959675767541762?s=19

@dapetcu21 did you have to implement the GoG Galaxy SDK?

1 Like

Yup. We implemented it for achievements. We should probably open source the native extension. I’ll see if I have some time this weekend to clean it up and put it in a separate project.

3 Likes

That would save my life. :sweat_smile:

1 Like

Nice! That would be very appreciated by @Alex_8BitSkull and others.

3 Likes

Here you go: https://github.com/dapetcu21/defold-gog-galaxy
Some assembly required

9 Likes

Massive thank you! :pray:

1 Like