The newest release adds Steam Stats functionality. You can find the full list of added features on the releases page.
If you find the release useful, please consider donating.
Greenworks is a MIT-licensed node.js addon allowing you to integrate your HTML5 app or game with Steamworks by exposing a number of Steamworks APIs to JavaScript.
Greenworks is developed by Greenheart Games, originally to enable Steam integration in Game Dev Tycoon, and has been open-sourced and used in other projects. The project is funded by Greenheart Games and other donors.
The project is built using NAN module to support different node versions.
Currently Greenworks supports:
- node v0.8, v0.10, v0.12, v4, v5, v6 and v7
- NW.js (formerly node-webkit) v0.8, v0.11 or above
- Electron (formerly atom-shell) v1.0.0 or above
Prebuilt binaries of Greenworks for NW.js & Electron can be found on the releases page.
Greenworks currently supports Steam Cloud, Steam Achievement and Workshop synchronization related methods.
API references are located in docs directory.
Before using Greenworks, you need to:
- Copy
steam_api.dll
/libsteam_api.dylib
/libsteam_api.so
(from<steam_sdk_path>/redistributable_bin/
) to<app-dir>/lib/
. - Copy
sdkencryptedappticket.dll
/libsdkencryptedappticket.dylib
/libsdkencryptedappticket.so
(from<steam_sdk-path>/public/steam/lib/
) to<greenworks_path>/lib
. - Create a
steam_appid.txt
file with your Steam AppID (or the Steamworks example AppID of 480) in the<greenworks_path>/
directory.
- The current user logged into Steam must own the Steam AppID specified in the
steam_appid.txt
file, or else the Greenworks initialization will fail. - Once Greenworks is initialized, Steam will show the current user logged into
Steam as "playing" the Steam AppID specified in the
steam_appid.txt
file. - If you are using the Steam AppID of a different/existing game after Greenworks is initialized, Steam will prevent the user from opening that game, saying that "that game is already open".
- If you are using Greenworks in an Electron renderer process, you must call
process.activateUvLoop()
before initializing Greenworks, or else the eventloop of Greenworks won't get run. For more information, see issue #61.
- Download the release binaries from releases page and unzip them.
- Copy
steam_api.dll
/libsteam_api.dylib
/libsteam_api.so
(from<steam_sdk_path>/redistributable_bin/
) to<greenworks_path>/lib
. Please make sure the architecture (32 bits or 64 bits) of the steam dynamic library is the same as NW.js's. - Copy
sdkencryptedappticket.dll
/libsdkencryptedappticket.dylib
/libsdkencryptedappticket.so
(from<steam_sdk-path>/public/steam/lib/
) to<greenworks_path>/lib
. - Create a
steam_appid.txt
file with your Steam AppID (or the steamworks example AppID) under<greenworks_path>/
directory (You only need the file for development. If you launch the game from Steam, Steam will automatically know the AppID of your game). - Create your NW.js app code under
<greenworks_path>/
directory.
A hello-world sample
Create index.html
:
<html>
<head>
<meta charset="utf-8">
<title>Hello Greenworks</title>
</head>
<body>
<h1>Greenworks Test</h1>
SteamAPI Init:
<script>
var greenworks = require('./greenworks');
document.write(greenworks.initAPI());
</script>
</body>
Create package.json
:
{
"name": "greenworks-nw-demo",
"main": "index.html"
}
The NW.js v0.11.2 hello-world demo directory on Mac OS X like:
|-- greenworks.js
|-- index.html
|-- lib
| |-- greenworks-linux32.node
| |-- greenworks-linux64.node
| |-- greenworks-osx32.node
| |-- greenworks-osx64.node
| |-- greenworks-win32.node
| |-- libsdkencryptedappticket.dylib
| `-- libsteam_api.dylib
|-- package.json
`-- steam_appid.txt
- Steamworks SDK 1.40
- nodejs
- node-gyp (or nw-gyp if you use NW.js)
To get the Steamworks SDK:
- Download it from Steam. (You will need to login with your Steam account first in order to access the downloads list.)
- Extract the contents of the zip file.
- The extracted contents will contain one subdirectory,
sdk
. Rename this tosteamworks_sdk
. - Copy this directory to
<greenworks_src_dir>/deps/
.
# Change to the Greenworks source directory
cd greenworks
# Install the dependencies
npm install
# Configure gyp project
node-gyp configure
# Build Greenworks addon
node-gyp rebuild
Once building is done, you can find greenworks-(linux/win/osx).node
under
build/Release
.
If you encounter any issues, please check the troubleshooting page out before creating an issue.
Using Greenworks in NW.js (before v0.13 and from v0.15), you need to use
nw-gyp instead of node-gyp
to build.
Note:
NW.js v0.13 and v0.14 don't require to use nw-gyp
. The native modules built
by node-gyp
are supported, see
tutorial.
NW.js v0.15+ needs nw-gyp
again see http://docs.nwjs.io/en/latest/For%20Users/Advanced/Use%20Native%20Node%20Modules.
Install additional needed tools depending on your platform see https://github.com/nwjs/nw-gyp#installation.
# install nw-gyp
sudo npm install -g nw-gyp
cd greenworks
# generate the building files
nw-gyp configure --target=<0.10.5 or other nw version> --arch=<x64 or ia32>
# If you have an error stating requiure('nan') fails then do a local
sudo npm install nan
# build Greenworks
nw-gyp build
# You will have error if you forget to install the additional tools as stated above, you may also
# experience an issue building ia32 on linux 64, try installing g++-multilib
sudo apt-get install g++-multilib
After building finished, you can find the greenworks-(linux/win/osx).node
binaries in build/Release
.
A sample NW.js application is provided samples/nw.js.
Greenworks builds a native addon for Node. Addons are very sensitive to which
version of Node you use. For this reason, Electron provides an
electron-rebuild
tool for rebuilding all of the addons in a node_modules
folder. This means
that building/installing Greenworks is a multi-step process.
- For demonstration purposes, we will be using the Electron Quick Start application (You can skip to step 4 if you are following along directly with your own application). Clone it:
git clone https://github.com/electron/electron-quick-start.git
cd electron-quick-start
- Install all of the modules needed for the Electron Quick Start application:
npm install
- Verify that the application works:
npm start
- Now, we can install Greenworks. However, we can't build it yet, because it does not have Steamworks yet:
npm install --save --ignore-scripts git+https://github.com/greenheartgames/greenworks.git
-
Provide the Steamworks dependency to Greenworks by following the steps from the "General Prerequisties" section earlier on the page ( You need to create and populate the
node_modules/greenworks/deps/steamworks_sdk
folder.). -
Now, installing Greenworks should succeed:
npm install
- We need to rebuild the module, so install
electron-rebuild
:
npm install --save-dev electron-rebuild
- Then, run it:
node_modules/.bin/electron-rebuild
- Finally, create a
steam_appid.txt
in the root of the application with the Steam AppID you want to use. For testing purposes, we can use480
, the AppID for Spacewar, which is the example game included in the Steamworks SDK (Everyone on Steam automatically owns this game by default.).
echo 480 > steam_appid.txt
Note the following things about the AppID that you specify in this file:
- The current user logged into Steam must own this AppID, or else the Greenworks initialization will fail.
- Once Greenworks is initialized, Steam will show the current user logged into Steam as "playing" this AppID.
- If you specify the AppID of a different/existing game, after Greenworks is initialized, Steam will prevent the user from opening that game, saying that "that game is already open".
- Overwrite the Electron Quick Start renderer.js with one that does some "Hello World"-style Greenworks code:
mv renderer.js renderer.original.js
cp node_modules/greenworks/sample/electron/main.js renderer.js
- Test it:
npm start
Electron's guide to
using native Node modules
explains that you can also use node-gyp
directly with custom settings to build
a native module for a given Electron version.
cd greenworks
HOME=~/.electron-gyp node-gyp rebuild --target=<1.2.3 or other versions> --arch=x64 --dist-url=https://atom.io/download/atom-shell
The --target
is the Electron version you're using (e.g. 1.2.3
), the --arch
may be either ia32
or x64
. (If you want to use 32-bit Electron, we recommend
installing it with the 32-bit version of node.)
After the node-gyp
command is finished, you can find the
greenworks-(linux/win/osx).node
binaries in build/Release
.
Greenworks uses Mocha framework to test the steamworks APIs.
Since Greenworks is interacting with Steamworks, you need to create a
steam_appid.txt
file with a valid Steam Game Application ID
(your own AppID or Steamworks example AppID) in the
<greenworks_src_dir>/test
directory, in order to run the tests.
cd greenworks
./test/run-test
See how to find the application ID for a Steam Game.
Greenworks is published under the MIT license. See LICENSE
file for details.
If you use Greenworks, please let us know at @GreenheartGames and feel free to add your product to our product list.
Please consider donating to the project: