I noticed the considerable contributions of Relfos (here) and thecocce (Lazarus forum) to the theme. Their approach requires to build a custom DLL (with Visual Studio) against the current Steamworks SDK, if I'm right. So every time the Steamworks SDK gets updated, someone has to update the custom DLL too, I guess. Perhaps you can stay with a certain SDK version over time. But if you don't have yet any SDK you have to download the current version and rely on an appropriate custom DLL.
Anyway the Steamworks API, although being a C++ construct, provides at least some simple C-functions for init and shut-down (steam_api.h). So in Pascal, after loading the steam_api.dll (win32), you can access those functions without any custom DLL:
Code:
unit steam;
{$H+}{$mode objfpc}
interface
uses
dynlibs, ctypes, sysutils;
const
steamlib = 'steam_api.dll';
function steam_init: longint;
implementation
var
steamlib_handle: tlibhandle = nilhandle;
var
steamapi_init: function(): boolean; cdecl = nil;
steamapi_shutdown: procedure(); cdecl = nil;
procedure steam_exit;
begin
steamapi_shutdown();
unloadlibrary(steamlib_handle);
end;
function steam_init: longint;
begin
steamlib_handle := loadlibrary(steamlib);
if steamlib_handle=nilhandle then exit(0); // no steam DLL, run without steam
addexitproc(@steam_exit);
pointer(steamapi_init) := getprocedureaddress(steamlib_handle, pchar('SteamAPI_Init'));
pointer(steamapi_shutdown) := getprocedureaddress(steamlib_handle, pchar('SteamAPI_Shutdown'));
if not steamapi_init() then exit(-1); // steam client not running, program should halt
result := 1; // ok
end;
end.
Code:
program steam_game;
uses
..., steam;
...
begin
...
if steam_init=-1 then begin
// show message: steam client not running
halt;
end;
...
end.
I'm using this right now in my own game project. The Steam overlay is showing up and you even can access it. Further you can ensure that the Steam client is running. But all the other common Steam features are not available this way.
Then I stumbled upon the release notes regarding Steamworks SDK v1.32 (February 2015). One note reads as follows:
Added an auto-generated "flat" C-style API for common Steamworks features (steam_api_flat.h).
At this point the exploration begins.
I want to continue in an upcoming post. But feel free already to comment, to correct me or to give some advice regarding the possibilities of using that "flat" C-style API.
Thanks!
Bookmarks