* * *

Author Topic: VALVE Steam® API Wrapper for Delphi/Lazarus [Open source]  (Read 13494 times)

ASTRON3D

  • Newbie
  • Posts: 3
VALVE Steam® API Wrapper for Delphi/Lazarus [Open source]
« on: January 05, 2015, 07:28:09 am »
VALVE Steam® API Wrapper 0.3 for Delphi/Lazarus
License: MIT

https://github.com/voliaandrey/steamwrapper

Tharon

  • New member
  • *
  • Posts: 33
Re: VALVE Steam® API Wrapper for Delphi/Lazarus [Open source]
« Reply #1 on: February 18, 2015, 11:51:04 am »
This is exactly what i was searching for, since i'm unsuccessfully trying to call Steam_Api.dll within lazarus.

But it give me "Page not found".

engkin

  • Hero Member
  • *****
  • Posts: 2115
Re: VALVE Steam® API Wrapper for Delphi/Lazarus [Open source]
« Reply #2 on: February 18, 2015, 01:06:19 pm »
A search for steamwrapper leads to:

https://github.com/thecocce/steamwrapper

Tharon

  • New member
  • *
  • Posts: 33
Re: VALVE Steam® API Wrapper for Delphi/Lazarus [Open source]
« Reply #3 on: February 20, 2015, 12:50:58 pm »
Thank you engkin.

Unfortunately, it doesn't seem to suit my needs. It requires to build a DLL in VC2010 and ship it with the application, but i don't want to do it (and i don't have or like VC2010).

I only need to call the function 'ActivateGameOverlayToWebPage' inside class 'isteamfriends' from Steam_API.dll.
I'able to use a published function inside a DLL, but don't know how to call if it's inside a class.

engkin

  • Hero Member
  • *****
  • Posts: 2115
Re: VALVE Steam® API Wrapper for Delphi/Lazarus [Open source]
« Reply #4 on: February 20, 2015, 03:23:12 pm »
According to its documentation:
Quote
Version 1.32 Steamworks SDK released 2/5/2015

The Steamworks SDK has been updated. Version 1.32 of the SDK adds C# bindings, a flat C-style API, improvements to the HTTP interface, and an initial release of the Steam Inventory Service.

Which means to me that you should be able to deal with DLL directly. Somewhere else I did see something like:
SteamFriends_ActivateGameOverlayToWebPage

Check if you have that export in your DLL or try to get the latest version.

Tharon

  • New member
  • *
  • Posts: 33
Re: VALVE Steam® API Wrapper for Delphi/Lazarus [Open source]
« Reply #5 on: February 21, 2015, 10:08:18 am »
You are always precious :D

I download the latest SDK and you was right,  all the functions in the DLL was published a couple of weeks ago. I didn't noticed and was using the old build.

The DLL loads now, and i can call the function but i always get a SIGSEGV error when doing it.

I tried two different methods :

Code: [Select]
Type
   MyFunction = Function(CustomUrl : PChar) : DWORD; Stdcall;
 Const
   APIload  = 'steam_api.dll';
   PassString : String = 'http://forum.lazarus.freepascal.org';


implementation

{$R *.lfm}

{ TForm1 }

Function SteamAPI_ISteamFriends_ActivateGameOverlayToWebPage(CustomUrl : Pchar) : DWord; stdcall; External APIload;

procedure TForm1.Button1Click(Sender: TObject);
Var
  sHandle : TLibHandle;
  Proc : MyFunction;
begin
  sHandle := LoadLibrary(APIload);
  If sHandle = dynlibs.NilHandle Then ShowMessage('load error');
  Proc := MyFunction(GetProcedureAddress(shandle, 'SteamAPI_ISteamFriends_ActivateGameOverlayToWebPage'));
  If Proc = Nil Then ShowMessage('error')
  Else Proc(Pchar(PassString));
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  If SteamAPI_ISteamFriends_ActivateGameOverlayToWebPage(pChar(PassString)) = 0 Then ShowMessage('ok');
end;     

Both of them are able to call the function, but both of them ends with a sigsegv at address 6E45188B

Code: [Select]
steam_api!SteamAPI_ISteamFriends_ActivateGameOverlayToWebPage
6E451880 55                       push   %ebp
6E451881 8bec                     mov    %esp,%ebp
6E451883 8b4d08                   mov    0x8(%ebp),%ecx
6E451886 ff750c                   pushl  0xc(%ebp)
6E451889 8b01                     mov    (%ecx),%eax
6E45188B ff5078                   call   *0x78(%eax)
6E45188E 5d                       pop    %ebp
6E45188F c3                       ret   

The function reference in the SDK is :

Code: [Select]
SteamFriends()->ActivateGameOverlayToWebPage( const char *pchURL )

engkin

  • Hero Member
  • *****
  • Posts: 2115
Re: VALVE Steam® API Wrapper for Delphi/Lazarus [Open source]
« Reply #6 on: February 21, 2015, 02:01:04 pm »
I see two issues:
  • Unless mentioned in the documentation, usually C code has cdecl calling convention.
  • Libraries have to be initialized or something before using them.

Looking around for an example landed me on this page. I don't know for sure but it seems that you do need to call some code that is equal to the following C++ code:
Code: [Select]
// Initialize Steamworks
Steamworks::Initialize();
and optionally you can check it is running:
Code: [Select]
   if(!SteamAPI_IsSteamRunning())
   {
  MessageBoxA(0, "Steam not detected. Please run Steam before running this program.", "Error", 0);
  return false;
   }
before calling:
Code: [Select]
   // Go to a website using STEAM browser
   if(window->KeyHit(Key::W)) SteamFriends()->ActivateGameOverlayToWebPage("http://www.leadwerks.com/");

Tharon

  • New member
  • *
  • Posts: 33
Re: VALVE Steam® API Wrapper for Delphi/Lazarus [Open source]
« Reply #7 on: February 21, 2015, 02:36:04 pm »
Sorry i didn't mention it (and was missing from my code) but i already initialize steamwors with the proper function.

Now i've checked if it was properly initialized and, no didn't initialize. This is why i get the sigsegv, since when steamworks isn't initalized the functions interface is't exposed.

now i'm using

Code: [Select]

Function SteamAPI_Init : Boolean; cdecl; External APIload;  // Tried even with stdcall

If SteamAPI_Init = True Then ShowMessage('ok');


But without any luck.

The  code you found mention is for checking if steam is running, but steam is running so there is no need to check. And that function also doesn't work if the dll isn't already initialized.

Tharon

  • New member
  • *
  • Posts: 33
Re: VALVE Steam® API Wrapper for Delphi/Lazarus [Open source]
« Reply #8 on: February 21, 2015, 02:45:13 pm »
Wait, i get it. It need the APPID code to initalize properly, but this is really strange. AppIds are granted only to final products, but the Steam SDK is free. I'm searching inside the documentation for a way to initialize the library without it.

Tharon

  • New member
  • *
  • Posts: 33
Re: VALVE Steam® API Wrapper for Delphi/Lazarus [Open source]
« Reply #9 on: February 21, 2015, 03:10:27 pm »
Ok, i give up for now. Seems to be beyond my actual knowledge :)

phroyt

  • Newbie
  • Posts: 1
Re: VALVE Steam® API Wrapper for Delphi/Lazarus [Open source]
« Reply #10 on: January 09, 2016, 05:20:36 am »
I hope it's not too late.
Below is a snippet of a working code in Delphi.

  • You must ensure that a Steam Client is running.
    If not, you always get false to SteamAPI_IsSteamRunning;
  • Use Delayed Load to SteamAPI.
    Declare everything as Function Vars and assing them as needed;

That's is a simple code that works:

Code: Pascal  [Select]
  1. unit Steam;
  2.  
  3. interface
  4.  
  5. function Initialize(Path: String): boolean;
  6. procedure ShutDown();
  7.  
  8. implementation
  9.  
  10. uses windows, sysutils;
  11.  
  12. const
  13.  {$IFDEF WIN32}
  14.     steamapi_dll = 'steam_api.dll';
  15.  {$ENDIF}
  16.  {$IFDEF WIN64}
  17.     steamapi_dll = 'steam_api64.dll';
  18.  {$ENDIF}
  19.  
  20. var
  21.   SteamPath: String;
  22.   dllHandle: Cardinal;
  23.  
  24.   //Steam Flat Mapping
  25.   SteamAPI_Init: procedure(); stdcall = nil;
  26.   SteamAPI_Shutdown: procedure(); stdcall = nil;
  27.   SteamAPI_IsSteamRunning: function(): Boolean; stdcall = nil;
  28.  
  29. function LoadAPI: boolean;
  30. var dll: string;
  31. begin
  32.   Result := False;
  33.   dll := SteamPath+'\'+steamapi_dll;
  34.   dllHandle := 0;
  35.  
  36.   if FileExists(dll) and (dllHandle = 0) then
  37.     dllHandle := LoadLibrary(PWideChar(dll));
  38.  
  39.   if dllHandle <= 32 then
  40.       MessageBox(0,'Error: could not load ' + steamapi_dll, 'Oops!', MB_OK)
  41.   else
  42.   begin
  43.     SteamAPI_Init := GetProcAddress(dllHandle, 'SteamAPI_Init');
  44.     SteamAPI_Shutdown := GetProcAddress(dllHandle, 'SteamAPI_Shutdown');
  45.     SteamAPI_IsSteamRunning := GetProcAddress(dllHandle, 'SteamAPI_IsSteamRunning');
  46.     Result := True;
  47.   end;
  48. end;
  49.  
  50. function Initialize(Path: String): boolean;
  51. begin
  52.   Result := False;
  53.   SteamPath := Path;
  54.   if not LoadAPI() then
  55.     Exit;
  56.  
  57.   if Assigned(SteamAPI_Init) then
  58.     SteamAPI_Init();
  59.  
  60.   if Assigned(SteamAPI_IsSteamRunning) then
  61.     if not Boolean(SteamAPI_IsSteamRunning()) then
  62.       MessageBox(0,'Error: Steam is not running!', 'Oops!', MB_OK);
  63.  
  64.   Result := True;
  65. end;
  66.  
  67. procedure ShutDown();
  68. begin
  69.  
  70.   if Assigned(SteamAPI_Shutdown) then
  71.     SteamAPI_Shutdown();
  72.  
  73. end;
  74.  
  75.  
  76. end.
  77.  

Sample Call:
Code: Pascal  [Select]
  1. procedure TfrmFecther.btnDota2Click(Sender: TObject);
  2. var FDota2_SteamAPI_Path: String;
  3. begin
  4.   FDota2_SteamAPI_Path := 'C:\Program Files (x86)\Steam\steamapps\common\dota 2 beta\game\bin\win32';
  5.   if Steam.Initialize(FDota2_SteamAPI_Path) then
  6.     begin
  7.         // Do Something
  8.     end;
  9. end;
  10.  
  11.  
  12. FDota2_SteamAPI_Path := 'C:\Program Files (x86)\Steam\steamapps\common\dota 2 beta\game\bin\win32';
  13.  

Best Regards,
Phroyt

sagvan

  • Newbie
  • Posts: 1
Re: VALVE Steam® API Wrapper for Delphi/Lazarus [Open source]
« Reply #11 on: February 29, 2016, 08:41:44 am »
Hello, I have a problem with some SteamCallbacks - they does not work :(

does not work:
SteamCallbacks.OnLeaderboardFindResult
SteamCallbacks.OnNumberOfCurrentPlayers
...and some others (OnIPCountry, OnPlaybackStatusHasChanged)


Source:
Code: [Select]
procedure OnLeaderboardFindResult(SteamLeaderboard: uint64; LeaderboardFod: uint8); cdecl;
begin
 showmessage('Callback: OnLeaderboardFindResult');
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
 if not(System_InitWrapper) then
  begin
    Showmessage('Steam wrapper init error. Please check your steam client and/or steam_appid.txt');
    Halt;
  end;

 SteamCallbacks.OnLeaderboardFindResult:=OnLeaderboardFindResult;

 System_RegisterCallbacks(SteamCallbacks);

 SteamUserStats_FindOrCreateLeaderboard(PAnsiChar('x'),k_ELeaderboardSortMethodAscending,k_ELeaderboardDisplayTypeNumeric);

 Timer1.Enabled := true;
end;

procedure TForm2.Timer1Timer(Sender: TObject);
begin
  System_RunCallbacks;
end;


This create a new Leaderboard named "x" (I see it correctly in steamworks web administration), but no callback is called, then I can't use it :(

cocce

  • Newbie
  • Posts: 3
Re: VALVE Steam® API Wrapper for Delphi/Lazarus [Open source]
« Reply #12 on: April 06, 2016, 09:49:16 pm »
Hi all, i m working to fix the delphi wrapper. First fix :  OnLeaderboardFindResult now works fine.

https://github.com/thecocce/steamwrapper

Stay tuned!

Cocce
« Last Edit: April 06, 2016, 09:51:04 pm by cocce »

cocce

  • Newbie
  • Posts: 3
Re: VALVE Steam® API Wrapper for Delphi/Lazarus [Open source]
« Reply #13 on: January 03, 2017, 02:55:21 pm »
Hi all, I fixed 2 more callbacks:

OnLeaderboardScoreUploaded
OnLeaderboardScoreDownloaded

Enjoy

TheCocce

sintetus

  • Newbie
  • Posts: 2
Re: VALVE Steam® API Wrapper for Delphi/Lazarus [Open source]
« Reply #14 on: May 27, 2017, 08:44:38 pm »
Thank you very much!

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus