-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #408 from Revadike/feature-legacycdkeysdumper-example
Add Legacy CD Keys Dumper Example
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const SteamUser = require("steam-user"); | ||
const fs = require("fs"); | ||
|
||
const credentials = { | ||
accountName: "username", // your steam username | ||
Check failure on line 5 in examples/legacycdkeysdumper.js GitHub Actions / lint / lint
|
||
password: "password", // your steam password | ||
Check failure on line 6 in examples/legacycdkeysdumper.js GitHub Actions / lint / lint
|
||
}; | ||
|
||
const client = new SteamUser({ | ||
enablePicsCache: true, | ||
}); | ||
|
||
client.on("loggedOn", () => { | ||
console.log("Logged on"); | ||
Check failure on line 14 in examples/legacycdkeysdumper.js GitHub Actions / lint / lint
|
||
}); | ||
|
||
client.on("ownershipCached", async () => { | ||
let apps = client.getOwnedApps({ | ||
excludeExpiring: false, | ||
excludeFree: false, | ||
excludeShared: false | ||
}).filter(appid => { | ||
// these keys should indicate presence of a legacy cd key | ||
return [ | ||
"hadthirdpartycdkey", | ||
"legacykeydisklocation", | ||
"legacykeyfromapp", | ||
"legacykeylinkedexternally", | ||
"legacykeyproofofpurchaseticket", | ||
"legacykeyregistrationmethod", | ||
"legacykeyregistrylocation", | ||
"showcdkeyinmenu", | ||
"showcdkeyonlaunch", | ||
"supportscdkeycopytoclipboard", | ||
"thirdpartycdkey", | ||
].some((key) => Object.keys((client.picsCache | ||
&& client.picsCache.apps[appid] | ||
&& client.picsCache.apps[appid].appinfo | ||
&& client.picsCache.apps[appid].appinfo.extended) || {}).map((k) => k.toLowerCase()) | ||
.includes(key)); | ||
}); | ||
|
||
console.log(`Requesting legacy cd keys for ${apps.length} owned apps...`); | ||
let keys = {}; | ||
for (let appid of apps) { | ||
try { | ||
let { key } = await client.getLegacyGameKey(appid); | ||
keys[appid] = key; | ||
} catch (err) { | ||
if (err.eresult !== SteamUser.EResult.Fail) { // usually just means no cd key present | ||
console.error(`App: ${appid}`, err); | ||
} | ||
} | ||
} | ||
fs.writeFileSync("legacy_keys.json", JSON.stringify(keys, null, 4)); | ||
console.log("Done! Logging off..."); | ||
client.logOff(); | ||
}); | ||
|
||
client.on("disconnected", () => process.exit(0)); | ||
|
||
credentials.logonID = Math.round(Date.now() / 1000); // To avoid getting kicked by LogonSessionReplaced | ||
client.logOn(credentials); |