/SteamworksForPython

SteamworksForPython fork used in Switchcars

Primary LanguagePythonMIT LicenseMIT

SteamworksForPython

Howdy! This is a branch of Easimer's SteamworksForPython in an attempt to bring a fully-functional Python module for Steam out for the public.

Feel free to fork or contribute to this module.

For a fuller tutorial, with images, on SteamworksPy please read our post: http://coaguco.tumblr.com/post/128240756897/steamworks-for-python-tutorial-linux.

Some Notes

While I am still tinkering away with this, here are some things to note:

  • You will need the Steamworks SDK
  • You will most likely need a Steamworks account, with a valid AppID, to use more advanced functions (set achievements, set stats, etc.)
  • You will need to be logged into Steam for anything to function, obviously. As it assumes the game is run from Steam itself and is online.
  • Steam Overlay will only work if your game is using OpenGL or D3D! Overlay will only work if the game is actually launched from Steam itself. Possible if the SteamRestart command is fired; however, this is not implemented yet in SteamworksPy.

To Do

  • Add in more features from the Steamworks SDK
  • Create a Mac version (I do not own a Mac, so someone who does that can help out would be greatly appreciated!)

How To

  1. Download this repo and unpack
  2. Download and unpack the Steamworks SDK
  3. Move the Steam header (steam) folder from /sdk/public/ into the unpacked repo for compiling
  4. Move the Steam API file from /sdk/redistributable_bin into the unpacked repo
  • For Linux, find libsteam_api.so
  • For Windows, find steam_api.dll or steam_api64.dll as well as steam_api.lib or steam_api64.lib
  1. Create the new DLL or SO file
  • For Linux:
    • Run the makefile from the repo
    • Alternately, you could just run something like:
    g++ -o SteamworksPy.so -shared -fPIC SteamworksPy.cpp -lsteam_api
    
  • For Windows:
    • Create a new DLL project in Visual Studio
    • New > Project
    • Templates > Visual C++ > Win32 > Win32 Project
    • Follow the wizard and pick the DLL Application Type
    • Add SteamworksPy.cpp to Source Files and steam_api.h from /steam/ folder to Header Files
    • Go to Project > Properties in the toolbar
    • Under C/C++ > Precompiled Headers, turn off Precompiled Header option
    • Under Linker > Input, add steam_api.lib or steam_api64.lib to Additional Dependenices
    • Clean and build
  1. Move the steamworks.py and new compiled SteamworkPy.so or SteamworksPy.dll from the unpacked repo into your project
  • You also will have to move over the libsteam_api.so or steam_api.dll as well
  1. Add the following to your to your main file or whichever file you plan on calling Steam from:
from steamworks import *
#Initialize Steam
Steam.Init()

From here you should be able to call various functions of the steamworks.py. A list of available functions is listed below; take a closer look at the steamworks.py for a better understanding. In addition, you should be able to read the Steamworks API documentation to see what all is available and cross-reference with the steamworks.py!

Features / Functions

  1. Init()
  • Starts up the Steam API
  1. GetDLCCount()
  • Get the total number of DLC installed for this game
  1. IsDlcInstalled()
  • Is a particular DLC installed for this game
  • You must pass the DLC's AppID
  1. RequestAppProofOfPurchaseKey()
  • Should return the game's serial number, if it exists
  1. GetFriendCount()
  • Get the number of friends the user has
  1. GetPlayerName()
  • Get the user's name
  1. GetPersonaState()
  • Get the user's current state
  1. ActivateGameOverlay()
  • This should activate the Steam Overlay
  • Useful for binding keys to
  1. MusicIsEnabled()
  • Check whether or not Steam Music is enabled
  1. MusicIsPlaying()
  • Is Steam Music currently playing something?
  1. MusicGetVolume()
  • Get the system's current volume level
  1. MusicPause()
  • Pause whatever Steam Music is playing currently
  1. MusicPlay()
  • Play whatever track Steam Music is on
  1. MusicPlayNext()
  • Play the next track in Steam Music
  1. MusicPlayPrevious()
  • Play the previous track in Steam Music
  1. MusicSetVolume()
  • Set the system's volume
  • Must pass a float between 0.0 and 1.0
  1. GetPlayerID()
  • Get the user's Steam ID number
  • Currently just returns 0
  1. GetPlayerSteamLevel()
  • Should return the user's Steam level
  1. ClearAchievement()
  • Clear the specified achievement from the user
  • Must pass achievement's name in Steam (eg. STEAM_ACHIEVE_1)
  1. GetAchievement()
  • Find whether or not the specified achievement is earned
  • Must pass achievement's name in Steam (eg. STEAM_ACHIEVE_1)
  1. GetStatFloat()
  • Get value of specified float statistic
  • Must pass statistic's name in Steam (eg. TOTAL_GAMES)
  1. GetStatInt()
  • Get value of specified integer statistic
  • Must pass statistic's name in Steam (eg. TOTAL_GAMES)
  1. ResetAllStats()
  • Resets all of the user's statistics, perhaps also achievements
  1. RequestCurrentStats()
  • Pulls all of the user's statistics and achievements
  • Should be called before calling any Get stats/achievement functions
  1. SetAchievement()
  • Set a particular achievement for the user
  • Must pass achievement's name in Steam (eg. STEAM_ACHIEVE_1)
  1. SetStat()
  • Set a particular statistic for the user; either INT or FLOAT
  • Must pass statistics's name and value in Steam (eg. TOTAL_GAMES, 4)
  1. StoreStats()
  • Sends all the statistics and achievements to Steam servers
  1. GetCurrentBatteryPower()
  • Get the user's battery power level
  1. GetIPCountry()
  • Get the two-digit code for the user's IP address
  1. GetSecondsSinceAppActive()
  • Get the number of seconds since the game started up
  1. GetSecondsSinceComputerActive()
  • Get the number of seconds since the user's computer was started
  1. GetServerRealTime()
  • Get the time from the server, probably
  1. IsOverlayEnabled()
  • Is the Steam overlay enabled
  1. IsSteamRunningInVR()
  • Is Steam's VR service running
  1. GetSteamUILanguage()
  • Gets the user's Steam UI language (eg. English, French, etc.)
  1. GetAppID()
  • Should return the game's App ID

Further Usage

I recommend trying the included tests to get an idea of how it works. Opening the test files will give you some insight on how to use it in your game, as well as looking through the Steamworks.py file itself. Also, don't hesitate to contact me for help or with questions. Or comment / open issue on GitHub.

More To Come

I am still digging through the code and trying to get more functions working. Some things like controller might not be necessary as Python can usually handle these; though they may have more to do with the new Steam Controller.