release/v1.3.3 #10
@@ -55,20 +55,13 @@ class SteamClientService {
|
|||||||
return path.join(this.steamPath, 'config', 'config.vdf');
|
return path.join(this.steamPath, 'config', 'config.vdf');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Safe Atomic Write: Writes to a temp file and renames it.
|
|
||||||
* This prevents file corruption if the app crashes during write.
|
|
||||||
*/
|
|
||||||
private safeWriteVdf(filePath: string, data: any) {
|
private safeWriteVdf(filePath: string, data: any) {
|
||||||
const tempPath = `${filePath}.tmp_${Date.now()}`;
|
const tempPath = `${filePath}.tmp_${Date.now()}`;
|
||||||
const dir = path.dirname(filePath);
|
const dir = path.dirname(filePath);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
||||||
const vdfContent = stringify(data);
|
const vdfContent = stringify(data);
|
||||||
fs.writeFileSync(tempPath, vdfContent, 'utf-8');
|
fs.writeFileSync(tempPath, vdfContent, 'utf-8');
|
||||||
|
|
||||||
// Atomic rename
|
|
||||||
fs.renameSync(tempPath, filePath);
|
fs.renameSync(tempPath, filePath);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(`[SteamClient] Atomic write failed for ${filePath}: ${e.message}`);
|
console.error(`[SteamClient] Atomic write failed for ${filePath}: ${e.message}`);
|
||||||
@@ -80,11 +73,9 @@ class SteamClientService {
|
|||||||
public startWatching(callback: (accounts: LocalSteamAccount[]) => void) {
|
public startWatching(callback: (accounts: LocalSteamAccount[]) => void) {
|
||||||
this.onAccountsChanged = callback;
|
this.onAccountsChanged = callback;
|
||||||
const loginUsersPath = this.getLoginUsersPath();
|
const loginUsersPath = this.getLoginUsersPath();
|
||||||
|
|
||||||
if (loginUsersPath && fs.existsSync(loginUsersPath)) {
|
if (loginUsersPath && fs.existsSync(loginUsersPath)) {
|
||||||
this.readLocalAccounts();
|
this.readLocalAccounts();
|
||||||
chokidar.watch(loginUsersPath, { persistent: true, ignoreInitial: true }).on('change', () => {
|
chokidar.watch(loginUsersPath, { persistent: true, ignoreInitial: true }).on('change', () => {
|
||||||
console.log(`[SteamClient] loginusers.vdf changed, re-scanning...`);
|
|
||||||
this.readLocalAccounts();
|
this.readLocalAccounts();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -93,64 +84,41 @@ class SteamClientService {
|
|||||||
private readLocalAccounts() {
|
private readLocalAccounts() {
|
||||||
const filePath = this.getLoginUsersPath();
|
const filePath = this.getLoginUsersPath();
|
||||||
if (!filePath || !fs.existsSync(filePath)) return;
|
if (!filePath || !fs.existsSync(filePath)) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const content = fs.readFileSync(filePath, 'utf-8');
|
const content = fs.readFileSync(filePath, 'utf-8');
|
||||||
if (!content.trim()) return; // Empty file
|
if (!content.trim()) return;
|
||||||
|
|
||||||
const data = parse(content) as any;
|
const data = parse(content) as any;
|
||||||
if (!data || !data.users) return;
|
if (!data || !data.users) return;
|
||||||
|
|
||||||
const accounts: LocalSteamAccount[] = [];
|
const accounts: LocalSteamAccount[] = [];
|
||||||
for (const [steamId64, userData] of Object.entries(data.users)) {
|
for (const [steamId64, userData] of Object.entries(data.users)) {
|
||||||
const user = userData as any;
|
const user = userData as any;
|
||||||
if (!user || !user.AccountName) continue;
|
if (!user || !user.AccountName) continue;
|
||||||
|
|
||||||
accounts.push({
|
accounts.push({
|
||||||
steamId: steamId64,
|
steamId: steamId64, accountName: user.AccountName,
|
||||||
accountName: user.AccountName,
|
|
||||||
personaName: user.PersonaName || user.AccountName,
|
personaName: user.PersonaName || user.AccountName,
|
||||||
timestamp: parseInt(user.Timestamp) || 0
|
timestamp: parseInt(user.Timestamp) || 0
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.onAccountsChanged) this.onAccountsChanged(accounts);
|
if (this.onAccountsChanged) this.onAccountsChanged(accounts);
|
||||||
} catch (error) {
|
} catch (error) { }
|
||||||
console.error('[SteamClient] Error parsing loginusers.vdf:', error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public extractAccountConfig(accountName: string): any | null {
|
public extractAccountConfig(accountName: string): any | null {
|
||||||
const configPath = this.getConfigVdfPath();
|
const configPath = this.getConfigVdfPath();
|
||||||
if (!configPath || !fs.existsSync(configPath)) return null;
|
if (!configPath || !fs.existsSync(configPath)) return null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const content = fs.readFileSync(configPath, 'utf-8');
|
const content = fs.readFileSync(configPath, 'utf-8');
|
||||||
const data = parse(content) as any;
|
const data = parse(content) as any;
|
||||||
const accounts = data?.InstallConfigStore?.Software?.Valve?.Steam?.Accounts;
|
const accounts = data?.InstallConfigStore?.Software?.Valve?.Steam?.Accounts;
|
||||||
return (accounts && accounts[accountName]) ? accounts[accountName] : null;
|
return (accounts && accounts[accountName]) ? accounts[accountName] : null;
|
||||||
} catch (e) {
|
} catch (e) { return null; }
|
||||||
console.error('[SteamClient] Failed to extract config.vdf data');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public injectAccountConfig(accountName: string, accountData: any) {
|
public injectAccountConfig(accountName: string, accountData: any) {
|
||||||
const configPath = this.getConfigVdfPath();
|
const configPath = this.getConfigVdfPath();
|
||||||
if (!configPath) return;
|
if (!configPath) return;
|
||||||
|
|
||||||
let data: any = {
|
let data: any = { InstallConfigStore: { Software: { Valve: { Steam: { Accounts: {} } } } } };
|
||||||
InstallConfigStore: {
|
|
||||||
Software: {
|
|
||||||
Valve: {
|
|
||||||
Steam: {
|
|
||||||
Accounts: {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (fs.existsSync(configPath)) {
|
if (fs.existsSync(configPath)) {
|
||||||
try {
|
try {
|
||||||
const content = fs.readFileSync(configPath, 'utf-8');
|
const content = fs.readFileSync(configPath, 'utf-8');
|
||||||
@@ -159,14 +127,24 @@ class SteamClientService {
|
|||||||
} catch (e) { }
|
} catch (e) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure safe nesting
|
const ensurePath = (obj: any, keys: string[]) => {
|
||||||
if (!data.InstallConfigStore) data.InstallConfigStore = {};
|
let curr = obj;
|
||||||
if (!data.InstallConfigStore.Software) data.InstallConfigStore.Software = {};
|
for (const key of keys) {
|
||||||
if (!data.InstallConfigStore.Software.Valve) data.InstallConfigStore.Software.Valve = {};
|
if (!curr[key] || typeof curr[key] !== 'object') curr[key] = {};
|
||||||
if (!data.InstallConfigStore.Software.Valve.Steam) data.InstallConfigStore.Software.Valve.Steam = {};
|
curr = curr[key];
|
||||||
if (!data.InstallConfigStore.Software.Valve.Steam.Accounts) data.InstallConfigStore.Software.Valve.Steam.Accounts = {};
|
}
|
||||||
|
return curr;
|
||||||
|
};
|
||||||
|
|
||||||
data.InstallConfigStore.Software.Valve.Steam.Accounts[accountName] = accountData;
|
const steamAccounts = ensurePath(data, ['InstallConfigStore', 'Software', 'Valve', 'Steam', 'Accounts']);
|
||||||
|
|
||||||
|
// FAILPROOF: Force crucial flags that Steam uses to decide session validity
|
||||||
|
steamAccounts[accountName] = {
|
||||||
|
...accountData,
|
||||||
|
RememberPassword: "1",
|
||||||
|
AllowAutoLogin: "1",
|
||||||
|
Timestamp: Math.floor(Date.now() / 1000).toString()
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.safeWriteVdf(configPath, data);
|
this.safeWriteVdf(configPath, data);
|
||||||
@@ -226,6 +204,7 @@ class SteamClientService {
|
|||||||
} catch (e) { }
|
} catch (e) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Injection of the actual authentication blob
|
||||||
if (accountConfig && accountName) {
|
if (accountConfig && accountName) {
|
||||||
this.injectAccountConfig(accountName, accountConfig);
|
this.injectAccountConfig(accountName, accountConfig);
|
||||||
}
|
}
|
||||||
@@ -239,13 +218,7 @@ class SteamClientService {
|
|||||||
|
|
||||||
for (const regPath of regLocations) {
|
for (const regPath of regLocations) {
|
||||||
if (!fs.existsSync(path.dirname(regPath))) continue;
|
if (!fs.existsSync(path.dirname(regPath))) continue;
|
||||||
|
let regData: any = { Registry: { HKCU: { Software: { Valve: { Steam: { AutoLoginUser: "", RememberPassword: "1", AlreadyLoggedIn: "1" } } } } } };
|
||||||
let regData: any = { Registry: { HKCU: { Software: { Valve: { Steam: {
|
|
||||||
AutoLoginUser: "",
|
|
||||||
RememberPassword: "1",
|
|
||||||
AlreadyLoggedIn: "1"
|
|
||||||
} } } } } };
|
|
||||||
|
|
||||||
if (fs.existsSync(regPath)) {
|
if (fs.existsSync(regPath)) {
|
||||||
try {
|
try {
|
||||||
const content = fs.readFileSync(regPath, 'utf-8');
|
const content = fs.readFileSync(regPath, 'utf-8');
|
||||||
@@ -254,13 +227,9 @@ class SteamClientService {
|
|||||||
} catch (e) { }
|
} catch (e) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deep merge helper
|
|
||||||
const ensurePath = (obj: any, keys: string[]) => {
|
const ensurePath = (obj: any, keys: string[]) => {
|
||||||
let curr = obj;
|
let curr = obj;
|
||||||
for (const key of keys) {
|
for (const key of keys) { if (!curr[key] || typeof curr[key] !== 'object') curr[key] = {}; curr = curr[key]; }
|
||||||
if (!curr[key] || typeof curr[key] !== 'object') curr[key] = {};
|
|
||||||
curr = curr[key];
|
|
||||||
}
|
|
||||||
return curr;
|
return curr;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -269,10 +238,7 @@ class SteamClientService {
|
|||||||
steamKey.RememberPassword = "1";
|
steamKey.RememberPassword = "1";
|
||||||
steamKey.AlreadyLoggedIn = "1";
|
steamKey.AlreadyLoggedIn = "1";
|
||||||
steamKey.WantsOfflineMode = "0";
|
steamKey.WantsOfflineMode = "0";
|
||||||
|
try { this.safeWriteVdf(regPath, regData); } catch (e) { }
|
||||||
try {
|
|
||||||
this.safeWriteVdf(regPath, regData);
|
|
||||||
} catch (e) { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user