steamworks-ffi-node 0.3.0 → 0.3.1
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/README.md +54 -10
- package/dist/internal/SteamAPICore.d.ts +198 -8
- package/dist/internal/SteamAPICore.d.ts.map +1 -1
- package/dist/internal/SteamAPICore.js +197 -8
- package/dist/internal/SteamAPICore.js.map +1 -1
- package/dist/internal/SteamAchievementManager.d.ts +602 -31
- package/dist/internal/SteamAchievementManager.d.ts.map +1 -1
- package/dist/internal/SteamAchievementManager.js +600 -31
- package/dist/internal/SteamAchievementManager.js.map +1 -1
- package/dist/internal/SteamLibraryLoader.d.ts.map +1 -1
- package/dist/internal/SteamLibraryLoader.js +16 -5
- package/dist/internal/SteamLibraryLoader.js.map +1 -1
- package/dist/internal/SteamStatsManager.d.ts +337 -42
- package/dist/internal/SteamStatsManager.d.ts.map +1 -1
- package/dist/internal/SteamStatsManager.js +335 -42
- package/dist/internal/SteamStatsManager.js.map +1 -1
- package/dist/steam.d.ts.map +1 -1
- package/dist/steam.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
[](https://www.npmjs.com/package/steamworks-ffi-node)
|
|
2
|
+
[](https://discord.gg/Ruzx4Z7cKr)
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
# Steamworks FFI - Steamworks SDK Integration
|
|
5
|
+
|
|
6
|
+
A production-ready TypeScript/JavaScript wrapper for the Steamworks SDK using Koffi FFI, designed for Node.js and Electron applications with **Steamworks SDK integration**.
|
|
4
7
|
|
|
5
8
|
> ✅ **No C++ Compilation Required**: Uses Koffi FFI for seamless installation without Visual Studio Build Tools!
|
|
6
9
|
|
|
@@ -21,7 +24,7 @@ A production-ready TypeScript/JavaScript wrapper for the Steamworks SDK using Ko
|
|
|
21
24
|
- ✅ User stats (get/set int/float, average rate tracking)
|
|
22
25
|
- ✅ Friend comparisons (compare stats with friends)
|
|
23
26
|
- ✅ Global statistics (worldwide aggregated data with history)
|
|
24
|
-
- **
|
|
27
|
+
- **Steamworks Integration**: Direct FFI calls to Steamworks C++ SDK
|
|
25
28
|
- **Cross-Platform**: Windows, macOS, and Linux support
|
|
26
29
|
- **Batteries Included**: All Steamworks redistributables bundled - no SDK download needed!
|
|
27
30
|
- **Electron Ready**: Perfect for Electron applications
|
|
@@ -51,14 +54,14 @@ npm install steamworks-ffi-node
|
|
|
51
54
|
```typescript
|
|
52
55
|
import Steam from 'steamworks-ffi-node';
|
|
53
56
|
|
|
54
|
-
// Initialize
|
|
57
|
+
// Initialize Steam connection
|
|
55
58
|
const steam = Steam.getInstance();
|
|
56
59
|
const initialized = steam.init({ appId: 480 }); // Your Steam App ID
|
|
57
60
|
|
|
58
61
|
if (initialized) {
|
|
59
62
|
// Get achievements from Steam servers
|
|
60
63
|
const achievements = await steam.getAllAchievements();
|
|
61
|
-
console.log('
|
|
64
|
+
console.log('Steam achievements:', achievements);
|
|
62
65
|
|
|
63
66
|
// Unlock achievement (permanent in Steam!)
|
|
64
67
|
await steam.unlockAchievement('ACH_WIN_ONE_GAME');
|
|
@@ -121,18 +124,18 @@ Complete documentation for all APIs is available in the [docs folder](https://gi
|
|
|
121
124
|
|
|
122
125
|
➡️ **[View Complete Documentation](https://github.com/ArtyProf/steamworks-ffi-node/blob/main/docs/README.md)**
|
|
123
126
|
|
|
124
|
-
## 🎮
|
|
127
|
+
## 🎮 Steamworks Integration
|
|
125
128
|
|
|
126
129
|
This library connects directly to the Steam client and Steamworks SDK:
|
|
127
130
|
|
|
128
131
|
```javascript
|
|
129
|
-
//
|
|
132
|
+
// Steam API - no mocking!
|
|
130
133
|
const steam = Steam.getInstance();
|
|
131
134
|
steam.init({ appId: 480 }); // Connects to actual Steam
|
|
132
135
|
|
|
133
136
|
// Live achievements from Steam servers
|
|
134
137
|
const achievements = await steam.getAllAchievements();
|
|
135
|
-
console.log(achievements); //
|
|
138
|
+
console.log(achievements); // Achievement data from your Steam app
|
|
136
139
|
|
|
137
140
|
// Permanent achievement unlock in Steam
|
|
138
141
|
await steam.unlockAchievement('YOUR_ACHIEVEMENT');
|
|
@@ -171,6 +174,45 @@ app.on('before-quit', () => {
|
|
|
171
174
|
});
|
|
172
175
|
```
|
|
173
176
|
|
|
177
|
+
### 📦 Packaging with ASAR
|
|
178
|
+
|
|
179
|
+
When packaging your Electron app with ASAR archives, **native modules must be unpacked**. The library automatically detects ASAR and looks for files in `.asar.unpacked`.
|
|
180
|
+
|
|
181
|
+
#### electron-builder Configuration
|
|
182
|
+
|
|
183
|
+
Add to your `package.json` or `electron-builder.yml`:
|
|
184
|
+
|
|
185
|
+
```json
|
|
186
|
+
{
|
|
187
|
+
"build": {
|
|
188
|
+
"asarUnpack": [
|
|
189
|
+
"node_modules/steamworks-ffi-node/**/*"
|
|
190
|
+
]
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
#### electron-forge Configuration
|
|
196
|
+
|
|
197
|
+
Add to your `forge.config.js`:
|
|
198
|
+
|
|
199
|
+
```javascript
|
|
200
|
+
module.exports = {
|
|
201
|
+
packagerConfig: {
|
|
202
|
+
asar: {
|
|
203
|
+
unpack: "**/{node_modules/steamworks-ffi-node}/**/*"
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
The library will automatically:
|
|
210
|
+
1. Detect if running inside an ASAR archive
|
|
211
|
+
2. Replace `.asar` with `.asar.unpacked` in the library path
|
|
212
|
+
3. Load the Steamworks SDK from the unpacked directory
|
|
213
|
+
|
|
214
|
+
This ensures native libraries work correctly in packaged Electron apps!
|
|
215
|
+
|
|
174
216
|
## 🔧 Requirements
|
|
175
217
|
|
|
176
218
|
- **Node.js**: 18+
|
|
@@ -202,7 +244,9 @@ All redistributable binaries are included in the package - no manual SDK downloa
|
|
|
202
244
|
|
|
203
245
|
### Electron-specific issues
|
|
204
246
|
- ❌ Initialized in renderer → **Solution**: Only initialize in main process
|
|
205
|
-
- ❌ Not cleaning up → **Solution**: Call `shutdown()` in `before-quit` event
|
|
247
|
+
- ❌ Not cleaning up → **Solution**: Call `shutdown()` in `before-quit` event
|
|
248
|
+
- ❌ "cannot open shared object file: Not a directory" (Linux) → **Solution**: Add `asarUnpack` configuration (see Electron Integration section above)
|
|
249
|
+
- ❌ Native module errors in packaged app → **Solution**: Ensure `steamworks-ffi-node` is in `asarUnpack` list
|
|
206
250
|
|
|
207
251
|
## 📄 License
|
|
208
252
|
|
|
@@ -213,4 +257,4 @@ MIT License - see LICENSE file for details.
|
|
|
213
257
|
This package includes redistributable binaries from the Steamworks SDK (© Valve Corporation).
|
|
214
258
|
These are distributed under the Steamworks SDK Access Agreement in accordance with Section 1.1(b).
|
|
215
259
|
|
|
216
|
-
See [THIRD_PARTY_LICENSES.md](https://github.com/ArtyProf/steamworks-ffi-node/blob/main/THIRD_PARTY_LICENSES.md) for full details.
|
|
260
|
+
See [THIRD_PARTY_LICENSES.md](https://github.com/ArtyProf/steamworks-ffi-node/blob/main/THIRD_PARTY_LICENSES.md) for full details.
|
|
@@ -1,45 +1,235 @@
|
|
|
1
1
|
import { SteamInitOptions, SteamStatus } from '../types';
|
|
2
2
|
import { SteamLibraryLoader } from './SteamLibraryLoader';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* SteamAPICore
|
|
5
|
+
*
|
|
6
|
+
* Core Steam API initialization and lifecycle management.
|
|
7
|
+
* Handles Steam client connection, interface management, and callback processing.
|
|
8
|
+
*
|
|
9
|
+
* This class manages the fundamental Steam API operations:
|
|
10
|
+
* - Initialization and shutdown of the Steam API
|
|
11
|
+
* - Interface retrieval (UserStats, User)
|
|
12
|
+
* - Status monitoring (Steam running, initialization state)
|
|
13
|
+
* - Callback processing for Steam events
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const loader = new SteamLibraryLoader();
|
|
18
|
+
* const apiCore = new SteamAPICore(loader);
|
|
19
|
+
*
|
|
20
|
+
* const success = apiCore.init({ appId: 480 });
|
|
21
|
+
* if (success) {
|
|
22
|
+
* console.log('Steam API initialized!');
|
|
23
|
+
* // Use Steam features...
|
|
24
|
+
* apiCore.shutdown();
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
5
27
|
*/
|
|
6
28
|
export declare class SteamAPICore {
|
|
29
|
+
/** Steam library loader for FFI function calls */
|
|
7
30
|
private libraryLoader;
|
|
31
|
+
/** Whether the Steam API has been successfully initialized */
|
|
8
32
|
private initialized;
|
|
33
|
+
/** The Steam App ID for this application */
|
|
9
34
|
private appId;
|
|
35
|
+
/** Pointer to the ISteamUserStats interface */
|
|
10
36
|
private userStatsInterface;
|
|
37
|
+
/** Pointer to the ISteamUser interface */
|
|
11
38
|
private userInterface;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new SteamAPICore instance
|
|
41
|
+
*
|
|
42
|
+
* @param libraryLoader - The Steam library loader for FFI calls
|
|
43
|
+
*/
|
|
12
44
|
constructor(libraryLoader: SteamLibraryLoader);
|
|
13
45
|
/**
|
|
14
|
-
* Initialize Steam API
|
|
46
|
+
* Initialize the Steam API
|
|
47
|
+
*
|
|
48
|
+
* Establishes connection to the Steam client and retrieves necessary interfaces.
|
|
49
|
+
* Creates steam_appid.txt file required by Steam, loads the Steamworks library,
|
|
50
|
+
* and initializes all necessary Steam interfaces.
|
|
51
|
+
*
|
|
52
|
+
* @param options - Initialization options containing the Steam App ID
|
|
53
|
+
* @returns true if initialization was successful, false otherwise
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const success = apiCore.init({ appId: 480 });
|
|
58
|
+
* if (success) {
|
|
59
|
+
* console.log('Connected to Steam for App ID:', 480);
|
|
60
|
+
* } else {
|
|
61
|
+
* console.error('Failed to initialize Steam API');
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* - Creates steam_appid.txt file in the current working directory
|
|
67
|
+
* - Sets SteamAppId environment variable
|
|
68
|
+
* - Automatically requests current stats from Steam servers
|
|
69
|
+
* - Runs callbacks to process initial Steam events
|
|
70
|
+
*
|
|
71
|
+
* @warning
|
|
72
|
+
* Requires Steam client to be running and user to be logged in
|
|
73
|
+
*
|
|
74
|
+
* Steamworks SDK Functions:
|
|
75
|
+
* - `SteamAPI_Init()` - Initialize the Steam API
|
|
76
|
+
* - `SteamAPI_IsSteamRunning()` - Check if Steam client is running
|
|
77
|
+
* - `SteamAPI_SteamUserStats_v013()` - Get ISteamUserStats interface
|
|
78
|
+
* - `SteamAPI_SteamUser_v023()` - Get ISteamUser interface
|
|
79
|
+
* - `SteamAPI_ISteamUserStats_RequestCurrentStats()` - Request current stats from Steam
|
|
80
|
+
* - `SteamAPI_RunCallbacks()` - Process Steam callbacks
|
|
15
81
|
*/
|
|
16
82
|
init(options: SteamInitOptions): boolean;
|
|
17
83
|
/**
|
|
18
|
-
* Shutdown Steam API
|
|
84
|
+
* Shutdown the Steam API
|
|
85
|
+
*
|
|
86
|
+
* Cleanly shuts down the Steam API connection and releases all interfaces.
|
|
87
|
+
* Should be called when the application is closing or Steam features are no longer needed.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* process.on('SIGINT', () => {
|
|
92
|
+
* apiCore.shutdown();
|
|
93
|
+
* process.exit(0);
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* @remarks
|
|
98
|
+
* - Safe to call multiple times (only shuts down if initialized)
|
|
99
|
+
* - Clears all interface pointers
|
|
100
|
+
* - Sets initialized state to false
|
|
101
|
+
*
|
|
102
|
+
* Steamworks SDK Functions:
|
|
103
|
+
* - `SteamAPI_Shutdown()` - Shutdown the Steam API
|
|
19
104
|
*/
|
|
20
105
|
shutdown(): void;
|
|
21
106
|
/**
|
|
22
|
-
* Get current Steam status
|
|
107
|
+
* Get the current Steam status
|
|
108
|
+
*
|
|
109
|
+
* Returns detailed status information including initialization state,
|
|
110
|
+
* App ID, and the current user's Steam ID.
|
|
111
|
+
*
|
|
112
|
+
* @returns Object containing initialization status, App ID, and Steam ID
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const status = apiCore.getStatus();
|
|
117
|
+
* console.log(`Initialized: ${status.initialized}`);
|
|
118
|
+
* console.log(`App ID: ${status.appId}`);
|
|
119
|
+
* console.log(`Steam ID: ${status.steamId}`);
|
|
120
|
+
* ```
|
|
121
|
+
*
|
|
122
|
+
* @remarks
|
|
123
|
+
* - Steam ID is '0' if not initialized or unable to retrieve
|
|
124
|
+
* - App ID is 0 if not initialized
|
|
125
|
+
*
|
|
126
|
+
* Steamworks SDK Functions:
|
|
127
|
+
* - `SteamAPI_ISteamUser_GetSteamID()` - Get current user's Steam ID
|
|
23
128
|
*/
|
|
24
129
|
getStatus(): SteamStatus;
|
|
25
130
|
/**
|
|
26
131
|
* Run Steam callbacks to process pending events
|
|
132
|
+
*
|
|
133
|
+
* Processes all pending Steam callbacks and events. Should be called regularly
|
|
134
|
+
* (e.g., in a game loop or timer) to ensure Steam events are processed promptly.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* // In a game loop or setInterval
|
|
139
|
+
* setInterval(() => {
|
|
140
|
+
* apiCore.runCallbacks();
|
|
141
|
+
* }, 100); // Every 100ms
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* @remarks
|
|
145
|
+
* - Safe to call even if not initialized (will be ignored)
|
|
146
|
+
* - Automatically called by init() and after stat/achievement operations
|
|
147
|
+
* - Required for receiving Steam events and callbacks
|
|
148
|
+
*
|
|
149
|
+
* Steamworks SDK Functions:
|
|
150
|
+
* - `SteamAPI_RunCallbacks()` - Process all pending Steam callbacks
|
|
27
151
|
*/
|
|
28
152
|
runCallbacks(): void;
|
|
29
153
|
/**
|
|
30
|
-
* Check if Steam client is running
|
|
154
|
+
* Check if the Steam client is running
|
|
155
|
+
*
|
|
156
|
+
* Verifies that the Steam client application is currently running on the user's system.
|
|
157
|
+
*
|
|
158
|
+
* @returns true if Steam is running, false otherwise
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* if (apiCore.isSteamRunning()) {
|
|
163
|
+
* console.log('Steam client is active');
|
|
164
|
+
* } else {
|
|
165
|
+
* console.warn('Steam client is not running');
|
|
166
|
+
* }
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* @remarks
|
|
170
|
+
* - Returns false if Steam API is not initialized
|
|
171
|
+
* - Safe to call at any time
|
|
172
|
+
*
|
|
173
|
+
* Steamworks SDK Functions:
|
|
174
|
+
* - `SteamAPI_IsSteamRunning()` - Check if Steam client is running
|
|
31
175
|
*/
|
|
32
176
|
isSteamRunning(): boolean;
|
|
33
177
|
/**
|
|
34
|
-
* Check if initialized
|
|
178
|
+
* Check if the Steam API is initialized
|
|
179
|
+
*
|
|
180
|
+
* Returns the current initialization state of the Steam API.
|
|
181
|
+
*
|
|
182
|
+
* @returns true if initialized and ready to use, false otherwise
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* if (!apiCore.isInitialized()) {
|
|
187
|
+
* console.error('Cannot perform Steam operations - not initialized');
|
|
188
|
+
* return;
|
|
189
|
+
* }
|
|
190
|
+
* ```
|
|
35
191
|
*/
|
|
36
192
|
isInitialized(): boolean;
|
|
37
193
|
/**
|
|
38
|
-
* Get
|
|
194
|
+
* Get the ISteamUserStats interface pointer
|
|
195
|
+
*
|
|
196
|
+
* Returns the native pointer to the ISteamUserStats interface, which is used
|
|
197
|
+
* for achievement and stats operations.
|
|
198
|
+
*
|
|
199
|
+
* @returns Pointer to ISteamUserStats interface, or null if not initialized
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* const userStats = apiCore.getUserStatsInterface();
|
|
204
|
+
* if (userStats) {
|
|
205
|
+
* // Use interface for stats/achievement operations
|
|
206
|
+
* }
|
|
207
|
+
* ```
|
|
208
|
+
*
|
|
209
|
+
* @remarks
|
|
210
|
+
* - Returns null if Steam API is not initialized
|
|
211
|
+
* - This is a native pointer for use with FFI calls
|
|
39
212
|
*/
|
|
40
213
|
getUserStatsInterface(): any;
|
|
41
214
|
/**
|
|
42
|
-
* Get
|
|
215
|
+
* Get the ISteamUser interface pointer
|
|
216
|
+
*
|
|
217
|
+
* Returns the native pointer to the ISteamUser interface, which is used
|
|
218
|
+
* for user identity operations.
|
|
219
|
+
*
|
|
220
|
+
* @returns Pointer to ISteamUser interface, or null if not initialized
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```typescript
|
|
224
|
+
* const user = apiCore.getUserInterface();
|
|
225
|
+
* if (user) {
|
|
226
|
+
* // Use interface for user operations
|
|
227
|
+
* }
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* @remarks
|
|
231
|
+
* - Returns null if Steam API is not initialized
|
|
232
|
+
* - This is a native pointer for use with FFI calls
|
|
43
233
|
*/
|
|
44
234
|
getUserInterface(): any;
|
|
45
235
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SteamAPICore.d.ts","sourceRoot":"","sources":["../../src/internal/SteamAPICore.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D
|
|
1
|
+
{"version":3,"file":"SteamAPICore.d.ts","sourceRoot":"","sources":["../../src/internal/SteamAPICore.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,YAAY;IACvB,kDAAkD;IAClD,OAAO,CAAC,aAAa,CAAqB;IAE1C,8DAA8D;IAC9D,OAAO,CAAC,WAAW,CAAkB;IAErC,4CAA4C;IAC5C,OAAO,CAAC,KAAK,CAAa;IAE1B,+CAA+C;IAC/C,OAAO,CAAC,kBAAkB,CAAa;IAEvC,0CAA0C;IAC1C,OAAO,CAAC,aAAa,CAAa;IAElC;;;;OAIG;gBACS,aAAa,EAAE,kBAAkB;IAI7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,IAAI,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO;IAmExC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,QAAQ,IAAI,IAAI;IAWhB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,SAAS,IAAI,WAAW;IAmBxB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,YAAY,IAAI,IAAI;IAUpB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,cAAc,IAAI,OAAO;IAYzB;;;;;;;;;;;;;;OAcG;IACH,aAAa,IAAI,OAAO;IAIxB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,qBAAqB,IAAI,GAAG;IAI5B;;;;;;;;;;;;;;;;;;;OAmBG;IACH,gBAAgB,IAAI,GAAG;CAGxB"}
|
|
@@ -37,18 +37,83 @@ exports.SteamAPICore = void 0;
|
|
|
37
37
|
const fs = __importStar(require("fs"));
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
40
|
+
* SteamAPICore
|
|
41
|
+
*
|
|
42
|
+
* Core Steam API initialization and lifecycle management.
|
|
43
|
+
* Handles Steam client connection, interface management, and callback processing.
|
|
44
|
+
*
|
|
45
|
+
* This class manages the fundamental Steam API operations:
|
|
46
|
+
* - Initialization and shutdown of the Steam API
|
|
47
|
+
* - Interface retrieval (UserStats, User)
|
|
48
|
+
* - Status monitoring (Steam running, initialization state)
|
|
49
|
+
* - Callback processing for Steam events
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const loader = new SteamLibraryLoader();
|
|
54
|
+
* const apiCore = new SteamAPICore(loader);
|
|
55
|
+
*
|
|
56
|
+
* const success = apiCore.init({ appId: 480 });
|
|
57
|
+
* if (success) {
|
|
58
|
+
* console.log('Steam API initialized!');
|
|
59
|
+
* // Use Steam features...
|
|
60
|
+
* apiCore.shutdown();
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
41
63
|
*/
|
|
42
64
|
class SteamAPICore {
|
|
65
|
+
/**
|
|
66
|
+
* Creates a new SteamAPICore instance
|
|
67
|
+
*
|
|
68
|
+
* @param libraryLoader - The Steam library loader for FFI calls
|
|
69
|
+
*/
|
|
43
70
|
constructor(libraryLoader) {
|
|
71
|
+
/** Whether the Steam API has been successfully initialized */
|
|
44
72
|
this.initialized = false;
|
|
73
|
+
/** The Steam App ID for this application */
|
|
45
74
|
this.appId = 0;
|
|
75
|
+
/** Pointer to the ISteamUserStats interface */
|
|
46
76
|
this.userStatsInterface = null;
|
|
77
|
+
/** Pointer to the ISteamUser interface */
|
|
47
78
|
this.userInterface = null;
|
|
48
79
|
this.libraryLoader = libraryLoader;
|
|
49
80
|
}
|
|
50
81
|
/**
|
|
51
|
-
* Initialize Steam API
|
|
82
|
+
* Initialize the Steam API
|
|
83
|
+
*
|
|
84
|
+
* Establishes connection to the Steam client and retrieves necessary interfaces.
|
|
85
|
+
* Creates steam_appid.txt file required by Steam, loads the Steamworks library,
|
|
86
|
+
* and initializes all necessary Steam interfaces.
|
|
87
|
+
*
|
|
88
|
+
* @param options - Initialization options containing the Steam App ID
|
|
89
|
+
* @returns true if initialization was successful, false otherwise
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const success = apiCore.init({ appId: 480 });
|
|
94
|
+
* if (success) {
|
|
95
|
+
* console.log('Connected to Steam for App ID:', 480);
|
|
96
|
+
* } else {
|
|
97
|
+
* console.error('Failed to initialize Steam API');
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @remarks
|
|
102
|
+
* - Creates steam_appid.txt file in the current working directory
|
|
103
|
+
* - Sets SteamAppId environment variable
|
|
104
|
+
* - Automatically requests current stats from Steam servers
|
|
105
|
+
* - Runs callbacks to process initial Steam events
|
|
106
|
+
*
|
|
107
|
+
* @warning
|
|
108
|
+
* Requires Steam client to be running and user to be logged in
|
|
109
|
+
*
|
|
110
|
+
* Steamworks SDK Functions:
|
|
111
|
+
* - `SteamAPI_Init()` - Initialize the Steam API
|
|
112
|
+
* - `SteamAPI_IsSteamRunning()` - Check if Steam client is running
|
|
113
|
+
* - `SteamAPI_SteamUserStats_v013()` - Get ISteamUserStats interface
|
|
114
|
+
* - `SteamAPI_SteamUser_v023()` - Get ISteamUser interface
|
|
115
|
+
* - `SteamAPI_ISteamUserStats_RequestCurrentStats()` - Request current stats from Steam
|
|
116
|
+
* - `SteamAPI_RunCallbacks()` - Process Steam callbacks
|
|
52
117
|
*/
|
|
53
118
|
init(options) {
|
|
54
119
|
try {
|
|
@@ -102,7 +167,26 @@ class SteamAPICore {
|
|
|
102
167
|
}
|
|
103
168
|
}
|
|
104
169
|
/**
|
|
105
|
-
* Shutdown Steam API
|
|
170
|
+
* Shutdown the Steam API
|
|
171
|
+
*
|
|
172
|
+
* Cleanly shuts down the Steam API connection and releases all interfaces.
|
|
173
|
+
* Should be called when the application is closing or Steam features are no longer needed.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* process.on('SIGINT', () => {
|
|
178
|
+
* apiCore.shutdown();
|
|
179
|
+
* process.exit(0);
|
|
180
|
+
* });
|
|
181
|
+
* ```
|
|
182
|
+
*
|
|
183
|
+
* @remarks
|
|
184
|
+
* - Safe to call multiple times (only shuts down if initialized)
|
|
185
|
+
* - Clears all interface pointers
|
|
186
|
+
* - Sets initialized state to false
|
|
187
|
+
*
|
|
188
|
+
* Steamworks SDK Functions:
|
|
189
|
+
* - `SteamAPI_Shutdown()` - Shutdown the Steam API
|
|
106
190
|
*/
|
|
107
191
|
shutdown() {
|
|
108
192
|
if (this.libraryLoader.isLoaded() && this.initialized) {
|
|
@@ -115,7 +199,27 @@ class SteamAPICore {
|
|
|
115
199
|
}
|
|
116
200
|
}
|
|
117
201
|
/**
|
|
118
|
-
* Get current Steam status
|
|
202
|
+
* Get the current Steam status
|
|
203
|
+
*
|
|
204
|
+
* Returns detailed status information including initialization state,
|
|
205
|
+
* App ID, and the current user's Steam ID.
|
|
206
|
+
*
|
|
207
|
+
* @returns Object containing initialization status, App ID, and Steam ID
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* const status = apiCore.getStatus();
|
|
212
|
+
* console.log(`Initialized: ${status.initialized}`);
|
|
213
|
+
* console.log(`App ID: ${status.appId}`);
|
|
214
|
+
* console.log(`Steam ID: ${status.steamId}`);
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
* @remarks
|
|
218
|
+
* - Steam ID is '0' if not initialized or unable to retrieve
|
|
219
|
+
* - App ID is 0 if not initialized
|
|
220
|
+
*
|
|
221
|
+
* Steamworks SDK Functions:
|
|
222
|
+
* - `SteamAPI_ISteamUser_GetSteamID()` - Get current user's Steam ID
|
|
119
223
|
*/
|
|
120
224
|
getStatus() {
|
|
121
225
|
let steamId = '0';
|
|
@@ -136,6 +240,25 @@ class SteamAPICore {
|
|
|
136
240
|
}
|
|
137
241
|
/**
|
|
138
242
|
* Run Steam callbacks to process pending events
|
|
243
|
+
*
|
|
244
|
+
* Processes all pending Steam callbacks and events. Should be called regularly
|
|
245
|
+
* (e.g., in a game loop or timer) to ensure Steam events are processed promptly.
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```typescript
|
|
249
|
+
* // In a game loop or setInterval
|
|
250
|
+
* setInterval(() => {
|
|
251
|
+
* apiCore.runCallbacks();
|
|
252
|
+
* }, 100); // Every 100ms
|
|
253
|
+
* ```
|
|
254
|
+
*
|
|
255
|
+
* @remarks
|
|
256
|
+
* - Safe to call even if not initialized (will be ignored)
|
|
257
|
+
* - Automatically called by init() and after stat/achievement operations
|
|
258
|
+
* - Required for receiving Steam events and callbacks
|
|
259
|
+
*
|
|
260
|
+
* Steamworks SDK Functions:
|
|
261
|
+
* - `SteamAPI_RunCallbacks()` - Process all pending Steam callbacks
|
|
139
262
|
*/
|
|
140
263
|
runCallbacks() {
|
|
141
264
|
if (this.initialized && this.libraryLoader.isLoaded()) {
|
|
@@ -148,7 +271,27 @@ class SteamAPICore {
|
|
|
148
271
|
}
|
|
149
272
|
}
|
|
150
273
|
/**
|
|
151
|
-
* Check if Steam client is running
|
|
274
|
+
* Check if the Steam client is running
|
|
275
|
+
*
|
|
276
|
+
* Verifies that the Steam client application is currently running on the user's system.
|
|
277
|
+
*
|
|
278
|
+
* @returns true if Steam is running, false otherwise
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```typescript
|
|
282
|
+
* if (apiCore.isSteamRunning()) {
|
|
283
|
+
* console.log('Steam client is active');
|
|
284
|
+
* } else {
|
|
285
|
+
* console.warn('Steam client is not running');
|
|
286
|
+
* }
|
|
287
|
+
* ```
|
|
288
|
+
*
|
|
289
|
+
* @remarks
|
|
290
|
+
* - Returns false if Steam API is not initialized
|
|
291
|
+
* - Safe to call at any time
|
|
292
|
+
*
|
|
293
|
+
* Steamworks SDK Functions:
|
|
294
|
+
* - `SteamAPI_IsSteamRunning()` - Check if Steam client is running
|
|
152
295
|
*/
|
|
153
296
|
isSteamRunning() {
|
|
154
297
|
if (this.initialized && this.libraryLoader.isLoaded()) {
|
|
@@ -163,19 +306,65 @@ class SteamAPICore {
|
|
|
163
306
|
return false;
|
|
164
307
|
}
|
|
165
308
|
/**
|
|
166
|
-
* Check if initialized
|
|
309
|
+
* Check if the Steam API is initialized
|
|
310
|
+
*
|
|
311
|
+
* Returns the current initialization state of the Steam API.
|
|
312
|
+
*
|
|
313
|
+
* @returns true if initialized and ready to use, false otherwise
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* ```typescript
|
|
317
|
+
* if (!apiCore.isInitialized()) {
|
|
318
|
+
* console.error('Cannot perform Steam operations - not initialized');
|
|
319
|
+
* return;
|
|
320
|
+
* }
|
|
321
|
+
* ```
|
|
167
322
|
*/
|
|
168
323
|
isInitialized() {
|
|
169
324
|
return this.initialized;
|
|
170
325
|
}
|
|
171
326
|
/**
|
|
172
|
-
* Get
|
|
327
|
+
* Get the ISteamUserStats interface pointer
|
|
328
|
+
*
|
|
329
|
+
* Returns the native pointer to the ISteamUserStats interface, which is used
|
|
330
|
+
* for achievement and stats operations.
|
|
331
|
+
*
|
|
332
|
+
* @returns Pointer to ISteamUserStats interface, or null if not initialized
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* ```typescript
|
|
336
|
+
* const userStats = apiCore.getUserStatsInterface();
|
|
337
|
+
* if (userStats) {
|
|
338
|
+
* // Use interface for stats/achievement operations
|
|
339
|
+
* }
|
|
340
|
+
* ```
|
|
341
|
+
*
|
|
342
|
+
* @remarks
|
|
343
|
+
* - Returns null if Steam API is not initialized
|
|
344
|
+
* - This is a native pointer for use with FFI calls
|
|
173
345
|
*/
|
|
174
346
|
getUserStatsInterface() {
|
|
175
347
|
return this.userStatsInterface;
|
|
176
348
|
}
|
|
177
349
|
/**
|
|
178
|
-
* Get
|
|
350
|
+
* Get the ISteamUser interface pointer
|
|
351
|
+
*
|
|
352
|
+
* Returns the native pointer to the ISteamUser interface, which is used
|
|
353
|
+
* for user identity operations.
|
|
354
|
+
*
|
|
355
|
+
* @returns Pointer to ISteamUser interface, or null if not initialized
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* ```typescript
|
|
359
|
+
* const user = apiCore.getUserInterface();
|
|
360
|
+
* if (user) {
|
|
361
|
+
* // Use interface for user operations
|
|
362
|
+
* }
|
|
363
|
+
* ```
|
|
364
|
+
*
|
|
365
|
+
* @remarks
|
|
366
|
+
* - Returns null if Steam API is not initialized
|
|
367
|
+
* - This is a native pointer for use with FFI calls
|
|
179
368
|
*/
|
|
180
369
|
getUserInterface() {
|
|
181
370
|
return this.userInterface;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SteamAPICore.js","sourceRoot":"","sources":["../../src/internal/SteamAPICore.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAI7B
|
|
1
|
+
{"version":3,"file":"SteamAPICore.js","sourceRoot":"","sources":["../../src/internal/SteamAPICore.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAI7B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAa,YAAY;IAgBvB;;;;OAIG;IACH,YAAY,aAAiC;QAjB7C,8DAA8D;QACtD,gBAAW,GAAY,KAAK,CAAC;QAErC,4CAA4C;QACpC,UAAK,GAAW,CAAC,CAAC;QAE1B,+CAA+C;QACvC,uBAAkB,GAAQ,IAAI,CAAC;QAEvC,0CAA0C;QAClC,kBAAa,GAAQ,IAAI,CAAC;QAQhC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,IAAI,CAAC,OAAyB;QAC5B,IAAI,CAAC;YACH,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;YAE3B,kCAAkC;YAClC,OAAO,CAAC,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YAE/C,uDAAuD;YACvD,MAA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