From c78fdbe9a4dc014711922b415a566dc11421c212 Mon Sep 17 00:00:00 2001 From: Revadike Date: Wed, 9 Mar 2022 06:31:11 +0100 Subject: [PATCH 1/4] Add Legacy CD Keys Dumper Example --- examples/legacycdkeysdumper.js | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 examples/legacycdkeysdumper.js diff --git a/examples/legacycdkeysdumper.js b/examples/legacycdkeysdumper.js new file mode 100644 index 00000000..161be147 --- /dev/null +++ b/examples/legacycdkeysdumper.js @@ -0,0 +1,38 @@ +/** + * SteamUser example - Legacy CD Keys Dumper + * + * Simply logs into Steam using account credentials and dumps the CD keys of all your owned apps to file as JSON + */ + +const SteamUser = require("steam-user"); +const fs = require("fs"); + +const client = new SteamUser({ + enablePicsCache: true, +}); + +client.on("loggedOn", () => { + console.log("Logged on!"); +}); + +client.on("ownershipCached", async () => { + let apps = client.getOwnedApps({ + excludeExpiring: false, + excludeFree: false, + excludeShared: false + }); + + + console.log("Requesting legacy cd keys for " + apps.length + " owned apps..."); + let keys = {}; + await Promise.all(apps.map(appid => client.getLegacyGameKey(appid).then(({key}) => keys[appid] = key).catch(() => {}))); + fs.writeFileSync("legacy_cd_keys.json", JSON.stringify(keys, null, 4)); + console.log("Done! Logging off..."); + client.logOff(); +}); + +client.logOn({ + accountName: "username", // change this to your steam username + password: "password", // change this to your steam password + logonID: Math.round(Date.now() / 1000) +}); \ No newline at end of file From e0b5d144910458c2f2fec12cee9abf0cbe70d9be Mon Sep 17 00:00:00 2001 From: Revadike Date: Wed, 9 Mar 2022 19:24:13 +0100 Subject: [PATCH 2/4] request one-by-one --- examples/legacycdkeysdumper.js | 46 +++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/examples/legacycdkeysdumper.js b/examples/legacycdkeysdumper.js index 161be147..9a010c12 100644 --- a/examples/legacycdkeysdumper.js +++ b/examples/legacycdkeysdumper.js @@ -1,9 +1,3 @@ -/** - * SteamUser example - Legacy CD Keys Dumper - * - * Simply logs into Steam using account credentials and dumps the CD keys of all your owned apps to file as JSON - */ - const SteamUser = require("steam-user"); const fs = require("fs"); @@ -12,7 +6,7 @@ const client = new SteamUser({ }); client.on("loggedOn", () => { - console.log("Logged on!"); + console.log("Logged on"); }); client.on("ownershipCached", async () => { @@ -20,19 +14,47 @@ client.on("ownershipCached", async () => { 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?.apps[appid]?.appinfo?.extended || {}).map(k => k.toLowerCase()).includes(key) + ); }); - + console.log("Requesting legacy cd keys for " + apps.length + " owned apps..."); let keys = {}; - await Promise.all(apps.map(appid => client.getLegacyGameKey(appid).then(({key}) => keys[appid] = key).catch(() => {}))); - fs.writeFileSync("legacy_cd_keys.json", JSON.stringify(keys, null, 4)); + for (let appid of apps) { + let { key } = await client.getLegacyGameKey(appid).catch(err => { + if (err.eresult !== 2) { // usually just means no cd key present + console.error(`App: ${appid}`, err); + } + return {}; + }); + if (key) { + keys[appid] = key; + } + } + fs.writeFileSync("legacy_keys.json", JSON.stringify(keys, null, 4)); console.log("Done! Logging off..."); client.logOff(); + process.exit(); }); client.logOn({ - accountName: "username", // change this to your steam username - password: "password", // change this to your steam password + accountName: "username", // your steam username + password: "password", // your steam password logonID: Math.round(Date.now() / 1000) }); \ No newline at end of file From a5b93c55bc051c9ff4befbc1f845ffa8119bdf58 Mon Sep 17 00:00:00 2001 From: Revadike Date: Wed, 9 Mar 2022 21:14:01 +0100 Subject: [PATCH 3/4] exit on disconnect --- examples/legacycdkeysdumper.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/legacycdkeysdumper.js b/examples/legacycdkeysdumper.js index 9a010c12..b29dbd84 100644 --- a/examples/legacycdkeysdumper.js +++ b/examples/legacycdkeysdumper.js @@ -50,9 +50,10 @@ client.on("ownershipCached", async () => { fs.writeFileSync("legacy_keys.json", JSON.stringify(keys, null, 4)); console.log("Done! Logging off..."); client.logOff(); - process.exit(); }); +client.on("disconnected", () => process.exit(0)); + client.logOn({ accountName: "username", // your steam username password: "password", // your steam password From a565e357e25f78984ec95937efc14308899a0616 Mon Sep 17 00:00:00 2001 From: Revadike Date: Sun, 16 Oct 2022 04:32:26 +0200 Subject: [PATCH 4/4] implemented feedback --- examples/legacycdkeysdumper.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/examples/legacycdkeysdumper.js b/examples/legacycdkeysdumper.js index b29dbd84..455f10b6 100644 --- a/examples/legacycdkeysdumper.js +++ b/examples/legacycdkeysdumper.js @@ -1,6 +1,11 @@ const SteamUser = require("steam-user"); const fs = require("fs"); +const credentials = { + accountName: "username", // your steam username + password: "password", // your steam password +}; + const client = new SteamUser({ enablePicsCache: true, }); @@ -28,23 +33,23 @@ client.on("ownershipCached", async () => { "showcdkeyonlaunch", "supportscdkeycopytoclipboard", "thirdpartycdkey", - ].some(key => - Object.keys(client.picsCache?.apps[appid]?.appinfo?.extended || {}).map(k => k.toLowerCase()).includes(key) - ); + ].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..."); + console.log(`Requesting legacy cd keys for ${apps.length} owned apps...`); let keys = {}; for (let appid of apps) { - let { key } = await client.getLegacyGameKey(appid).catch(err => { - if (err.eresult !== 2) { // usually just means no cd key present + 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); } - return {}; - }); - if (key) { - keys[appid] = key; } } fs.writeFileSync("legacy_keys.json", JSON.stringify(keys, null, 4)); @@ -54,8 +59,5 @@ client.on("ownershipCached", async () => { client.on("disconnected", () => process.exit(0)); -client.logOn({ - accountName: "username", // your steam username - password: "password", // your steam password - logonID: Math.round(Date.now() / 1000) -}); \ No newline at end of file +credentials.logonID = Math.round(Date.now() / 1000); // To avoid getting kicked by LogonSessionReplaced +client.logOn(credentials);