steamworks.js-timmy 0.1.15 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Gabriel Francisco Dos Santos
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Gabriel Francisco Dos Santos
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,88 +1,7 @@
1
- [![Build Status](https://github.com/ceifa/steamworks.js/actions/workflows/publish.yml/badge.svg)](https://github.com/ceifa/steamworks.js/actions/workflows/publish.yml)
2
- [![npm](https://img.shields.io/npm/v/steamworks.js.svg)](https://npmjs.com/package/steamworks.js)
3
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
- [![Chat](https://img.shields.io/discord/663831597690257431?label=chat&logo=discord)](https://discord.gg/H6B7UE7fMY)
5
-
6
- # Steamworks.js
7
-
8
- A modern implementation of the Steamworks SDK for HTML/JS and NodeJS based applications.
9
-
10
- ## Why
11
-
12
- I used [greenworks](https://github.com/greenheartgames/greenworks) for a long time and it's great, but I gave up for the following reasons.
13
-
14
- * It's not being maintained anymore.
15
- * It's not up to date.
16
- * It's not context-aware.
17
- * You have to build the binaries by yourself.
18
- * Don't have typescript definitions.
19
- * The API it's not trustful.
20
- * The API implement callbacks instead of return flags or promises.
21
- * I hate C++.
22
-
23
- ## API
24
-
25
- ```js
26
- const steamworks = require('steamworks.js')
27
-
28
- // You can pass an appId, or don't pass anything and use a steam_appid.txt file
29
- const client = steamworks.init(480)
30
-
31
- // Print Steam username
32
- console.log(client.localplayer.getName())
33
-
34
- // Tries to activate an achievement
35
- if (client.achievement.activate('ACHIEVEMENT')) {
36
- // ...
37
- }
38
- ```
39
-
40
- You can refer to the [declarations file](https://github.com/ceifa/steamworks.js/blob/main/client.d.ts) to check the API support and get more detailed documentation of each function.
41
-
42
- ## Installation
43
-
44
- To use steamworks.js you don't have to build anything, just install it from npm:
45
-
46
- ```sh
47
- $: npm i steamworks.js
48
- ```
49
-
50
- ### Electron
51
-
52
- Steamworks.js is a native module and cannot be used by default in the renderer process. To enable the usage of native modules on the renderer process, the following configurations should be made on `main.js`:
53
-
54
- ```js
55
- const mainWindow = new BrowserWindow({
56
- // ...
57
- webPreferences: {
58
- // ...
59
- contextIsolation: false,
60
- nodeIntegration: true
61
- }
62
- })
63
- ```
64
-
65
- To make the steam overlay working, call the `electronEnableSteamOverlay` on the end of your `main.js` file:
66
-
67
- ```js
68
- require('steamworks.js').electronEnableSteamOverlay()
69
- ```
70
-
71
- For the production build, copy the relevant distro files from `sdk/redistributable_bin/{YOUR_DISTRO}` into the root of your build. If you are using electron-forge, look for [#75](https://github.com/ceifa/steamworks.js/issues/75).
72
-
73
-
74
- ## How to build
75
-
76
- > You **only** need to build if you are going to change something on steamworks.js code, if you are looking to just consume the library or use it in your game, refer to the [installation section](#installation).
77
-
78
- Make sure you have the latest [node.js](https://nodejs.org/en/), [Rust](https://www.rust-lang.org/tools/install) and [Clang](https://rust-lang.github.io/rust-bindgen/requirements.html). We also need [Steam](https://store.steampowered.com/about/) installed and running.
79
-
80
- Install dependencies with `npm install` and then run `npm run build:debug` to build the library.
81
-
82
- There is no way to build for all targets easily. The good news is that you don't need to. You can develop and test on your current target, and open a PR. When the code is merged to main, a github action will build for all targets and publish a new version.
83
-
84
- ### Testing Electron
85
-
86
- Go to the [test/electron](./test/electron) directory. There, you can run `npm install` and then `npm start` to run the Electron app.
87
-
88
- Click "activate overlay" to test the overlay.
1
+ # steamworks.js-timmy
2
+
3
+ package with added features and newer steam API
4
+
5
+ yum
6
+
7
+ specifically tailored for [NEODITRONIX](https://store.steampowered.com/app/3782120/NEODITRONIX/), please play it!!!!
package/callbacks.d.ts CHANGED
@@ -1,56 +1,56 @@
1
- import client = require('./client')
2
-
3
- export const enum ChatMemberStateChange {
4
- /** This user has joined or is joining the lobby. */
5
- Entered,
6
- /** This user has left or is leaving the lobby. */
7
- Left,
8
- /** User disconnected without leaving the lobby first. */
9
- Disconnected,
10
- /** The user has been kicked. */
11
- Kicked,
12
- /** The user has been kicked and banned. */
13
- Banned,
14
- }
15
-
16
- export interface CallbackReturns {
17
- [client.callback.SteamCallback.PersonaStateChange]: {
18
- steam_id: bigint
19
- flags: { bits: number }
20
- }
21
- [client.callback.SteamCallback.SteamServersConnected]: {}
22
- [client.callback.SteamCallback.SteamServersDisconnected]: {
23
- reason: number
24
- }
25
- [client.callback.SteamCallback.SteamServerConnectFailure]: {
26
- reason: number
27
- still_retrying: boolean
28
- }
29
- [client.callback.SteamCallback.LobbyDataUpdate]: {
30
- lobby: bigint
31
- member: bigint
32
- success: boolean
33
- }
34
- [client.callback.SteamCallback.LobbyChatUpdate]: {
35
- lobby: bigint
36
- user_changed: bigint
37
- making_change: bigint
38
- member_state_change: ChatMemberStateChange
39
- }
40
- [client.callback.SteamCallback.P2PSessionRequest]: {
41
- remote: bigint
42
- }
43
- [client.callback.SteamCallback.P2PSessionConnectFail]: {
44
- remote: bigint
45
- error: number
46
- }
47
- [client.callback.SteamCallback.GameLobbyJoinRequested]: {
48
- lobby_steam_id: bigint
49
- friend_steam_id: bigint
50
- }
51
- [client.callback.SteamCallback.MicroTxnAuthorizationResponse]: {
52
- app_id: number
53
- order_id: number | bigint
54
- authorized: boolean
55
- }
56
- }
1
+ import client = require('./client')
2
+
3
+ export const enum ChatMemberStateChange {
4
+ /** This user has joined or is joining the lobby. */
5
+ Entered,
6
+ /** This user has left or is leaving the lobby. */
7
+ Left,
8
+ /** User disconnected without leaving the lobby first. */
9
+ Disconnected,
10
+ /** The user has been kicked. */
11
+ Kicked,
12
+ /** The user has been kicked and banned. */
13
+ Banned,
14
+ }
15
+
16
+ export interface CallbackReturns {
17
+ [client.callback.SteamCallback.PersonaStateChange]: {
18
+ steam_id: bigint
19
+ flags: { bits: number }
20
+ }
21
+ [client.callback.SteamCallback.SteamServersConnected]: {}
22
+ [client.callback.SteamCallback.SteamServersDisconnected]: {
23
+ reason: number
24
+ }
25
+ [client.callback.SteamCallback.SteamServerConnectFailure]: {
26
+ reason: number
27
+ still_retrying: boolean
28
+ }
29
+ [client.callback.SteamCallback.LobbyDataUpdate]: {
30
+ lobby: bigint
31
+ member: bigint
32
+ success: boolean
33
+ }
34
+ [client.callback.SteamCallback.LobbyChatUpdate]: {
35
+ lobby: bigint
36
+ user_changed: bigint
37
+ making_change: bigint
38
+ member_state_change: ChatMemberStateChange
39
+ }
40
+ [client.callback.SteamCallback.P2PSessionRequest]: {
41
+ remote: bigint
42
+ }
43
+ [client.callback.SteamCallback.P2PSessionConnectFail]: {
44
+ remote: bigint
45
+ error: number
46
+ }
47
+ [client.callback.SteamCallback.GameLobbyJoinRequested]: {
48
+ lobby_steam_id: bigint
49
+ friend_steam_id: bigint
50
+ }
51
+ [client.callback.SteamCallback.MicroTxnAuthorizationResponse]: {
52
+ app_id: number
53
+ order_id: number | bigint
54
+ authorized: boolean
55
+ }
56
+ }
@@ -31,7 +31,10 @@ module.exports.init = (appId) => {
31
31
  internalInit(appId)
32
32
 
33
33
  clearInterval(runCallbacksInterval)
34
- runCallbacksInterval = setInterval(runCallbacks, 1000 / 30)
34
+ runCallbacksInterval = setInterval(() => {
35
+ // console.log("Running callbacks")
36
+ runCallbacks()
37
+ }, 1000 / 120)
35
38
 
36
39
  return api
37
40
  }
package/index.js CHANGED
@@ -1,86 +1,89 @@
1
- const { platform, arch } = process
2
-
3
- /** @typedef {typeof import('./client.d')} Client */
4
- /** @type {Client} */
5
- let nativeBinding = undefined
6
-
7
- if (platform === 'win32' && arch === 'x64') {
8
- nativeBinding = require('./dist/win64/steamworksjs.win32-x64-msvc.node')
9
- } else if (platform === 'linux' && arch === 'x64') {
10
- nativeBinding = require('./dist/linux64/steamworksjs.linux-x64-gnu.node')
11
- } else if (platform === 'darwin') {
12
- if (arch === 'x64') {
13
- nativeBinding = require('./dist/osx/steamworksjs.darwin-x64.node')
14
- } else if (arch === 'arm64') {
15
- nativeBinding = require('./dist/osx/steamworksjs.darwin-arm64.node')
16
- }
17
- } else {
18
- throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
19
- }
20
-
21
- let runCallbacksInterval = undefined
22
-
23
- /**
24
- * Initialize the steam client or throw an error if it fails
25
- * @param {number} [appId] - App ID of the game to load, if undefined, will search for a steam_appid.txt file
26
- * @returns {Omit<Client, 'init' | 'runCallbacks'>}
27
- */
28
- module.exports.init = (appId) => {
29
- const { init: internalInit, runCallbacks, restartAppIfNecessary, ...api } = nativeBinding
30
-
31
- internalInit(appId)
32
-
33
- clearInterval(runCallbacksInterval)
34
- runCallbacksInterval = setInterval(runCallbacks, 1000 / 30)
35
-
36
- return api
37
- }
38
-
39
- /**
40
- * @description Shuts down the steam client
41
- */
42
- module.exports.shutdown = () => {
43
- clearInterval(runCallbacksInterval)
44
- nativeBinding.shutdownClient()
45
- runCallbacksInterval = undefined
46
- }
47
-
48
- /**
49
- * @param {number} appId - App ID of the game to load
50
- * {@link https://partner.steamgames.com/doc/api/steam_api#SteamAPI_RestartAppIfNecessary}
51
- * @returns {boolean}
52
- */
53
- module.exports.restartAppIfNecessary = (appId) => nativeBinding.restartAppIfNecessary(appId);
54
-
55
- /**
56
- * Enable the steam overlay on electron
57
- * @param {boolean} [disableEachFrameInvalidation] - Should attach a single pixel to be rendered each frame
58
- */
59
- module.exports.electronEnableSteamOverlay = (disableEachFrameInvalidation) => {
60
- const electron = require('electron')
61
- if (!electron) {
62
- throw new Error('Electron module not found')
63
- }
64
-
65
- electron.app.commandLine.appendSwitch('in-process-gpu')
66
- electron.app.commandLine.appendSwitch('disable-direct-composition')
67
-
68
- if (!disableEachFrameInvalidation) {
69
- /** @param {electron.BrowserWindow} browserWindow */
70
- const attachFrameInvalidator = (browserWindow) => {
71
- browserWindow.steamworksRepaintInterval = setInterval(() => {
72
- if (browserWindow.isDestroyed()) {
73
- clearInterval(browserWindow.steamworksRepaintInterval)
74
- } else if (!browserWindow.webContents.isPainting()) {
75
- browserWindow.webContents.invalidate()
76
- }
77
- }, 1000 / 60)
78
- }
79
-
80
- electron.BrowserWindow.getAllWindows().forEach(attachFrameInvalidator)
81
- electron.app.on('browser-window-created', (_, bw) => attachFrameInvalidator(bw))
82
- }
83
- }
84
-
85
- const SteamCallback = nativeBinding.callback.SteamCallback
1
+ const { platform, arch } = process
2
+
3
+ /** @typedef {typeof import('./client.d')} Client */
4
+ /** @type {Client} */
5
+ let nativeBinding = undefined
6
+
7
+ if (platform === 'win32' && arch === 'x64') {
8
+ nativeBinding = require('./dist/win64/steamworksjs.win32-x64-msvc.node')
9
+ } else if (platform === 'linux' && arch === 'x64') {
10
+ nativeBinding = require('./dist/linux64/steamworksjs.linux-x64-gnu.node')
11
+ } else if (platform === 'darwin') {
12
+ if (arch === 'x64') {
13
+ nativeBinding = require('./dist/osx/steamworksjs.darwin-x64.node')
14
+ } else if (arch === 'arm64') {
15
+ nativeBinding = require('./dist/osx/steamworksjs.darwin-arm64.node')
16
+ }
17
+ } else {
18
+ throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
19
+ }
20
+
21
+ let runCallbacksInterval = undefined
22
+
23
+ /**
24
+ * Initialize the steam client or throw an error if it fails
25
+ * @param {number} [appId] - App ID of the game to load, if undefined, will search for a steam_appid.txt file
26
+ * @returns {Omit<Client, 'init' | 'runCallbacks'>}
27
+ */
28
+ module.exports.init = (appId) => {
29
+ const { init: internalInit, runCallbacks, restartAppIfNecessary, ...api } = nativeBinding
30
+
31
+ internalInit(appId)
32
+
33
+ clearInterval(runCallbacksInterval)
34
+ runCallbacksInterval = setInterval(() => {
35
+ // console.log("Running callbacks")
36
+ runCallbacks()
37
+ }, 1000 / 120)
38
+
39
+ return api
40
+ }
41
+
42
+ /**
43
+ * @description Shuts down the steam client
44
+ */
45
+ module.exports.shutdown = () => {
46
+ clearInterval(runCallbacksInterval)
47
+ nativeBinding.shutdownClient()
48
+ runCallbacksInterval = undefined
49
+ }
50
+
51
+ /**
52
+ * @param {number} appId - App ID of the game to load
53
+ * {@link https://partner.steamgames.com/doc/api/steam_api#SteamAPI_RestartAppIfNecessary}
54
+ * @returns {boolean}
55
+ */
56
+ module.exports.restartAppIfNecessary = (appId) => nativeBinding.restartAppIfNecessary(appId);
57
+
58
+ /**
59
+ * Enable the steam overlay on electron
60
+ * @param {boolean} [disableEachFrameInvalidation] - Should attach a single pixel to be rendered each frame
61
+ */
62
+ module.exports.electronEnableSteamOverlay = (disableEachFrameInvalidation) => {
63
+ const electron = require('electron')
64
+ if (!electron) {
65
+ throw new Error('Electron module not found')
66
+ }
67
+
68
+ electron.app.commandLine.appendSwitch('in-process-gpu')
69
+ electron.app.commandLine.appendSwitch('disable-direct-composition')
70
+
71
+ if (!disableEachFrameInvalidation) {
72
+ /** @param {electron.BrowserWindow} browserWindow */
73
+ const attachFrameInvalidator = (browserWindow) => {
74
+ browserWindow.steamworksRepaintInterval = setInterval(() => {
75
+ if (browserWindow.isDestroyed()) {
76
+ clearInterval(browserWindow.steamworksRepaintInterval)
77
+ } else if (!browserWindow.webContents.isPainting()) {
78
+ browserWindow.webContents.invalidate()
79
+ }
80
+ }, 1000 / 60)
81
+ }
82
+
83
+ electron.BrowserWindow.getAllWindows().forEach(attachFrameInvalidator)
84
+ electron.app.on('browser-window-created', (_, bw) => attachFrameInvalidator(bw))
85
+ }
86
+ }
87
+
88
+ const SteamCallback = nativeBinding.callback.SteamCallback
86
89
  module.exports.SteamCallback = SteamCallback
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamworks.js-timmy",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "napi": {
@@ -23,18 +23,17 @@
23
23
  "license": "MIT",
24
24
  "devDependencies": {
25
25
  "@napi-rs/cli": "3.3.1",
26
+ "@types/node": "*",
26
27
  "electron": "24.2.0",
27
28
  "rimraf": "6.0.1",
28
29
  "typescript": "5.5.3"
29
30
  },
30
- "dependencies": {
31
- "@types/node": "*"
32
- },
33
31
  "engines": {
34
32
  "node": ">= 14"
35
33
  },
36
34
  "scripts": {
37
35
  "build": "npm run types && node build --release",
36
+ "prepare": "npm run build",
38
37
  "build:debug": "node build",
39
38
  "prune": "rimraf dist target client.d.ts",
40
39
  "format": "cargo clippy --fix --allow-staged && cargo fmt",