Skip to content

larsiusprime/SteamWrap

Repository files navigation

SteamWrap

Simple Haxe native extension Steam API wrapper. This code originally shipped in Papers, Please and the changes in this fork were made for the PC release of rymdkapsel. Windows, OS X and Linux/SteamOS builds are supported.

Current Features:

  • Achievements & Leaderboards
  • Steam Controller Support
  • UGC (user generated content)
  • Stats (not well-tested)

This repository comes with prebuilt binaries, which means it should work "out of the box".

(I'm in the process of updating the binaries, right now all it has is Windows)

Dependencies / Requirements:

  • Haxe 3.2 or greater
  • hxcpp 3.2.205 or greater
  • OpenFL 3.6 or greater
  • lime 2.8.3 or greater

Probably works with NME as well but I'm unsure of the requirements there. Ask Hugh.

To include steamwrap.ndll in your OpenFL or NME project:

  1. Install the library:

    latest git version: haxelib git steamwrap https://github.com/larsiusprime/SteamWrap

  2. Add the following nodes to your project.xml (assumes OpenFL or NME for now):

   <!-- Replace the question marks with your Steam App ID -->
   <setenv name="STEAM_APP_ID" value="??????" />

   <!-- OS X only: Set this value to the same value as the file property of your <app> node, this is needed to embed things into the generated .app file -->
   <!-- Setting this for other platforms won't do any harm, so you can safely leave it enabled for everything -->
   <set name="APP_FILE" value="??????" />
   
   <haxelib name="steamwrap"/>
  1. If you are doing non-Steam builds as well, it is practical to wrap this in a conditional. Run your builds as: openfl test <platform> -Dsteam to enable it, for example: openfl test windows -Dsteam.
   <section if="steam">
   	<!-- Steam specifics go here -->
   </section>
**!!!!!!!!!!!!!!!!! IMPORTANT !!!!!!!!!!!!!!!!!!!**

**This extension will automatically create a steam_appid.txt in your binary folder.**
**Do not ship your game with this file. Make sure it's stripped during the publishing stage.**

**Compiling with the "-Dfinal" flag should suppress creation of the steam_appid.txt**

```openfl test windows -Dsteam -Dfinal``` (for instance)

**!!!!!!!!!!!!!!!!! IMPORTANT !!!!!!!!!!!!!!!!!!!**
  1. Platform specific notes:

Linux

  • Make sure libsteam_api.so is sitting next to steamwrap.ndll
  • You will need a launch script to ensure libraries are loaded from the righ location. An example (Test.sh) is provided in the example folder
    • When you release your game on Steam, set this launch script as your executable, NOT the raw linux binary itself

Usage:

See steamwrap/example/Test.hx for a basic example.

To build steamwrap.ndll from source:

Automatic steps

  1. Run setup.bat (windows) or setup.sh (mac/linux) and enter the values it asks you for

Or you can set it up manually:


Manual steps:

  1. Copy the hxcpp headers:

     HAXE_DIR/lib/hxcpp/VERSION/include/hx/*.h -> STEAMWRAP_DIR/native/include/hx/*.h
    
  2. Copy the Steam SDK headers and libs:

     STEAMSDK_DIR/public/steam/*.h -> native/include/steam/*.h
     STEAMSDK_DIR/redistributable_bin/steam_api.dll -> native/lib/win32/
     STEAMSDK_DIR/redistributable_bin/steam_api.lib -> native/lib/win32/
     STEAMSDK_DIR/redistributable_bin/win64/steam_api64.dll -> native/lib/win64/
     STEAMSDK_DIR/redistributable_bin/win64/steam_api64.lib -> native/lib/win64/
     STEAMSDK_DIR/redistributable_bin/osx32/libsteam_api.dylib -> native/lib/osx64/
     STEAMSDK_DIR/redistributable_bin/linux32/libsteam_api.so -> native/lib/linux32/
     STEAMSDK_DIR/redistributable_bin/linux64/libsteam_api.so -> native/lib/linux64/
    
  3. Put some files in the build dir:

    Windows:

    	ndll/Windows/steam_appid.txt
    	STEAMSDK_DIR/redistributable_bin/steam_api.dll -> ndll/Windows/
    
    	ndll/Windows64/steam_appid.txt
    	STEAMSDK_DIR/redistributable_bin/steam_api64.dll -> ndll/Windows64/
    

    Mac:

    	ndll/Mac64/steam_appid.txt
    	STEAMSDK_DIR/redistributable_bin/steam_api.lib -> ndll/Mac64/
    

    Linux:

    	ndll/Linux/steam_appid.txt
    	STEAMSDK_DIR/redistributable_bin/steam_api.so -> ndll/Linux/
    	
    	ndll/Linux64/steam_appid.txt
    	STEAMSDK_DIR/redistributable_bin/steam_api.so -> ndll/Linux64/
    

    WHAT THIS DOES:

    The steam_api dll/dylib/so file must be next to your platform's steamwrap.ndll file in order for the extension to work. The dll/dylib/so file has all of the actual Steam API functionality, and the ndll file allows your Haxe project to communicate with it.

    As for the steam_appid.txt file, it's only there to make the "Test" program work. That's because the "Test" program will appear in your platform's ndll/ folder when you use the "build.bat" or "build" script to compile it.

    In order for your test program to work it must be able to find:

    • steamwrap.ndll (so Haxe can talk to Steam)
    • steam_api.dll/dylib/so (to provide the Steam API)
    • steam_appid.txt (to make the Steam Client recognize your app as a particular Steam Game when testing)

Final Steps:

  1. Run the "build" script (it's a basic haxelib command shortcut). steamwrap.ndll will be output to ndll/[PLATFORM]

Note: For linux you should have g++-multilib installed.

That's great, but we want to make sure it works! Let's run something with it. If you run the Test program now, you'll notice it exits immediately, asking you to supply an app ID.

  1. Edit steamwrap/example/Test.hx to include your Steam App ID and achievement ID's, etc.

    Now you are ready to compile example/Test.hx. Run the build script again.

  2. Start the Steam client, leave it open in the background, and run the Test app to make sure it connects.

Note: If you're running on Linux, you should run the "Test.sh" launcher script, not the "Test" binary directory

About

Haxe native extension for the Steam API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages