Files
Nils Pukropp 64fe49e58e
Some checks failed
Build and Release / build (push) Has been cancelled
init
2026-02-21 01:48:48 +01:00

240 lines
10 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.steamClient = void 0;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const os_1 = __importDefault(require("os"));
const simple_vdf_1 = require("simple-vdf");
const chokidar_1 = __importDefault(require("chokidar"));
class SteamClientService {
steamPath = null;
onAccountsChanged = null;
constructor() {
this.detectSteamPath();
}
detectSteamPath() {
const platform = os_1.default.platform();
const home = os_1.default.homedir();
if (platform === 'win32') {
const possiblePaths = [
'C:\\Program Files (x86)\\Steam',
'C:\\Program Files\\Steam'
];
this.steamPath = possiblePaths.find(p => fs_1.default.existsSync(p)) || null;
}
else if (platform === 'linux') {
const possiblePaths = [
path_1.default.join(home, '.steam/steam'),
path_1.default.join(home, '.local/share/Steam'),
path_1.default.join(home, '.var/app/com.valvesoftware.Steam/.steam/steam')
];
this.steamPath = possiblePaths.find(p => fs_1.default.existsSync(p)) || null;
}
if (this.steamPath) {
console.log(`[SteamClient] Detected Steam path: ${this.steamPath}`);
}
}
getLoginUsersPath() {
if (!this.steamPath)
return null;
return path_1.default.join(this.steamPath, 'config', 'loginusers.vdf');
}
getConfigVdfPath() {
if (!this.steamPath)
return null;
return path_1.default.join(this.steamPath, 'config', 'config.vdf');
}
startWatching(callback) {
this.onAccountsChanged = callback;
const loginUsersPath = this.getLoginUsersPath();
if (loginUsersPath && fs_1.default.existsSync(loginUsersPath)) {
this.readLocalAccounts();
chokidar_1.default.watch(loginUsersPath, { persistent: true }).on('change', () => {
this.readLocalAccounts();
});
}
}
readLocalAccounts() {
const filePath = this.getLoginUsersPath();
if (!filePath || !fs_1.default.existsSync(filePath))
return;
try {
const content = fs_1.default.readFileSync(filePath, 'utf-8');
const data = (0, simple_vdf_1.parse)(content);
if (!data || !data.users)
return;
const accounts = [];
for (const [steamId64, userData] of Object.entries(data.users)) {
const user = userData;
accounts.push({
steamId: steamId64,
accountName: user.AccountName,
personaName: user.PersonaName,
timestamp: parseInt(user.Timestamp) || 0
});
}
if (this.onAccountsChanged)
this.onAccountsChanged(accounts);
}
catch (error) {
console.error('[SteamClient] Error parsing loginusers.vdf:', error);
}
}
extractAccountConfig(accountName) {
const configPath = this.getConfigVdfPath();
if (!configPath || !fs_1.default.existsSync(configPath))
return null;
try {
const content = fs_1.default.readFileSync(configPath, 'utf-8');
const data = (0, simple_vdf_1.parse)(content);
const accounts = data?.InstallConfigStore?.Software?.Valve?.Steam?.Accounts;
if (accounts && accounts[accountName]) {
return accounts[accountName];
}
}
catch (e) {
console.error('[SteamClient] Failed to extract config.vdf data');
}
return null;
}
injectAccountConfig(accountName, accountData) {
const configPath = this.getConfigVdfPath();
if (!configPath)
return;
// Create directory if it doesn't exist
const configDir = path_1.default.dirname(configPath);
if (!fs_1.default.existsSync(configDir))
fs_1.default.mkdirSync(configDir, { recursive: true });
let data = { InstallConfigStore: { Software: { Valve: { Steam: { Accounts: {} } } } } };
if (fs_1.default.existsSync(configPath)) {
try {
const content = fs_1.default.readFileSync(configPath, 'utf-8');
data = (0, simple_vdf_1.parse)(content);
}
catch (e) { }
}
// Ensure structure exists
if (!data.InstallConfigStore)
data.InstallConfigStore = {};
if (!data.InstallConfigStore.Software)
data.InstallConfigStore.Software = {};
if (!data.InstallConfigStore.Software.Valve)
data.InstallConfigStore.Software.Valve = {};
if (!data.InstallConfigStore.Software.Valve.Steam)
data.InstallConfigStore.Software.Valve.Steam = {};
if (!data.InstallConfigStore.Software.Valve.Steam.Accounts)
data.InstallConfigStore.Software.Valve.Steam.Accounts = {};
data.InstallConfigStore.Software.Valve.Steam.Accounts[accountName] = accountData;
try {
fs_1.default.writeFileSync(configPath, (0, simple_vdf_1.stringify)(data));
console.log(`[SteamClient] Injected login config for ${accountName} into config.vdf`);
}
catch (e) {
console.error('[SteamClient] Failed to write config.vdf');
}
}
async setAutoLoginUser(accountName, accountConfig, steamId) {
const platform = os_1.default.platform();
const loginUsersPath = this.getLoginUsersPath();
if (loginUsersPath) {
const configDir = path_1.default.dirname(loginUsersPath);
if (!fs_1.default.existsSync(configDir))
fs_1.default.mkdirSync(configDir, { recursive: true });
let data = { users: {} };
if (fs_1.default.existsSync(loginUsersPath)) {
try {
const content = fs_1.default.readFileSync(loginUsersPath, 'utf-8');
data = (0, simple_vdf_1.parse)(content);
}
catch (e) { }
}
if (!data.users)
data.users = {};
let found = false;
for (const [id, user] of Object.entries(data.users)) {
const u = user;
if (u.AccountName.toLowerCase() === accountName.toLowerCase()) {
u.mostrecent = "1";
u.RememberPassword = "1";
u.AllowAutoLogin = "1";
u.WantsOfflineMode = "0";
u.SkipOfflineModeWarning = "1";
u.WasNonInteractive = "0";
found = true;
}
else {
u.mostrecent = "0";
}
}
if (!found && steamId) {
console.log(`[SteamClient] Provisioning user ${accountName} into loginusers.vdf`);
data.users[steamId] = {
AccountName: accountName,
PersonaName: accountName,
RememberPassword: "1",
mostrecent: "1",
AllowAutoLogin: "1",
WantsOfflineMode: "0",
SkipOfflineModeWarning: "1",
WasNonInteractive: "0",
Timestamp: Math.floor(Date.now() / 1000).toString()
};
}
try {
fs_1.default.writeFileSync(loginUsersPath, (0, simple_vdf_1.stringify)(data));
}
catch (e) {
console.error('[SteamClient] Failed to write loginusers.vdf');
}
}
if (accountConfig) {
this.injectAccountConfig(accountName, accountConfig);
}
if (platform === 'linux') {
const regLocations = [
path_1.default.join(os_1.default.homedir(), '.steam', 'registry.vdf'),
path_1.default.join(os_1.default.homedir(), '.steam', 'steam', 'registry.vdf')
];
for (const regPath of regLocations) {
let regData = { Registry: { HKCU: { Software: { Valve: { Steam: {} } } } } };
if (fs_1.default.existsSync(regPath)) {
try {
const content = fs_1.default.readFileSync(regPath, 'utf-8');
regData = (0, simple_vdf_1.parse)(content);
}
catch (e) { }
}
else {
const regDir = path_1.default.dirname(regPath);
if (!fs_1.default.existsSync(regDir))
fs_1.default.mkdirSync(regDir, { recursive: true });
}
const setPath = (obj, keys, val) => {
let curr = obj;
for (let i = 0; i < keys.length - 1; i++) {
if (!curr[keys[i]])
curr[keys[i]] = {};
curr = curr[keys[i]];
}
curr[keys[keys.length - 1]] = val;
};
const steamReg = ['Registry', 'HKCU', 'Software', 'Valve', 'Steam'];
setPath(regData, [...steamReg, 'AutoLoginUser'], accountName);
setPath(regData, [...steamReg, 'RememberPassword'], "1");
setPath(regData, [...steamReg, 'AlreadyLoggedIn'], "1");
setPath(regData, [...steamReg, 'WantsOfflineMode'], "0");
try {
fs_1.default.writeFileSync(regPath, (0, simple_vdf_1.stringify)(regData));
console.log(`[SteamClient] Registry updated: ${regPath}`);
}
catch (e) { }
}
}
return true;
}
}
exports.steamClient = new SteamClientService();