Last active
October 25, 2018 20:09
-
-
Save and3rson/74106f671f72680cf0d87c1ea47dda56 to your computer and use it in GitHub Desktop.
Using `libsteam_api.so` from Python via `ctypes.CDLL`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Hint: use steam_api_interop.cs for function signatures. | |
# Luckily libsteam_api.so has all of the methods demangled out of the box. | |
import ctypes | |
# Specify path to libsteam_api.so here | |
so = ctypes.CDLL('../sdk/redistributable_bin/linux64/libsteam_api.so') | |
so.SteamAPI_Init() | |
so.SteamClient.restype = ctypes.c_void_p | |
steamclient = so.SteamClient() | |
print('SteamClient:', steamclient) | |
so.SteamAPI_ISteamClient_CreateSteamPipe.argtypes = [ | |
ctypes.c_void_p | |
] | |
so.SteamAPI_ISteamClient_CreateSteamPipe.restype = ctypes.c_uint | |
hsteampipe = so.SteamAPI_ISteamClient_CreateSteamPipe(steamclient) | |
print('HSteamPipe:', hsteampipe) | |
so.SteamAPI_ISteamClient_ConnectToGlobalUser.argtypes = [ | |
ctypes.c_void_p, | |
ctypes.c_uint | |
] | |
so.SteamAPI_ISteamClient_ConnectToGlobalUser.restype = ctypes.c_uint | |
hsteamuser = so.SteamAPI_ISteamClient_ConnectToGlobalUser(steamclient, hsteampipe) | |
print('HSteamUser (global):', hsteamuser) | |
so.SteamAPI_ISteamClient_GetISteamUser.argtypes = [ | |
ctypes.c_void_p, | |
ctypes.c_uint, | |
ctypes.c_uint, | |
ctypes.c_char_p | |
] | |
so.SteamAPI_ISteamClient_GetISteamUser.restype = ctypes.c_void_p | |
isteamuser = so.SteamAPI_ISteamClient_GetISteamUser(steamclient, hsteamuser, hsteampipe, b'SteamUser019') | |
print('ISteamUser:', isteamuser) | |
so.SteamAPI_ISteamClient_GetISteamFriends.argtypes = [ | |
ctypes.c_void_p, | |
ctypes.c_uint, | |
ctypes.c_uint, | |
ctypes.c_char_p | |
] | |
so.SteamAPI_ISteamClient_GetISteamFriends.restype = ctypes.c_void_p | |
isteamfriends = so.SteamAPI_ISteamClient_GetISteamFriends(steamclient, hsteamuser, hsteampipe, b'SteamFriends015') | |
print('ISteamFriends:', isteamfriends) | |
so.SteamAPI_ISteamUser_GetSteamID.argtypes = [ctypes.c_void_p] | |
so.SteamAPI_ISteamUser_GetSteamID.restype = ctypes.c_ulong | |
steamid = so.SteamAPI_ISteamUser_GetSteamID(isteamuser) | |
print('SteamID:', steamid) | |
so.SteamAPI_ISteamFriends_GetPersonaName.argtypes = [ctypes.c_void_p] | |
so.SteamAPI_ISteamFriends_GetPersonaName.restype = ctypes.c_char_p | |
persona_name = so.SteamAPI_ISteamFriends_GetPersonaName(isteamfriends) | |
print('Persona name:', persona_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment