Merge pull request #1779 from hydralauncher/feat/steam-local-cache-achievements

feat: steam local cache achievements
This commit is contained in:
Zamitto
2025-09-01 14:13:41 -03:00
committed by GitHub
14 changed files with 140 additions and 18 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "hydralauncher",
"version": "3.6.3",
"version": "3.6.4",
"description": "Hydra",
"main": "./out/main/index.js",
"author": "Los Broxas",

View File

@@ -379,6 +379,7 @@
"installing_common_redist": "Installing…",
"show_download_speed_in_megabytes": "Show download speed in megabytes per second",
"extract_files_by_default": "Extract files by default after download",
"enable_steam_achievements": "Enable search for Steam achievements",
"achievement_custom_notification_position": "Achievement custom notification position",
"top-left": "Top left",
"top-center": "Top center",

View File

@@ -364,6 +364,7 @@
"installing_common_redist": "Instalando…",
"show_download_speed_in_megabytes": "Exibir taxas de download em megabytes por segundo",
"extract_files_by_default": "Extrair arquivos automaticamente após o download",
"enable_steam_achievements": "Habilitar busca por conquistas da Steam",
"enable_achievement_custom_notifications": "Habilitar notificações customizadas de conquistas",
"top-left": "Superior esquerdo",
"top-center": "Superior central",

View File

@@ -41,4 +41,4 @@ export const appVersion = app.getVersion() + (isStaging ? "-staging" : "");
export const ASSETS_PATH = path.join(SystemPath.getPath("userData"), "Assets");
export const MAIN_LOOP_INTERVAL = 1500;
export const MAIN_LOOP_INTERVAL = 2000;

View File

@@ -3,6 +3,7 @@ import { mergeAchievements } from "./merge-achievements";
import fs, { readdirSync } from "node:fs";
import {
findAchievementFileInExecutableDirectory,
findAchievementFileInSteamPath,
findAchievementFiles,
findAllAchievementFiles,
getAlternativeObjectIds,
@@ -43,6 +44,10 @@ const watchAchievementsWindows = async () => {
gameAchievementFiles.push(
...findAchievementFileInExecutableDirectory(game)
);
gameAchievementFiles.push(
...(await findAchievementFileInSteamPath(game))
);
}
for (const file of gameAchievementFiles) {
@@ -61,10 +66,8 @@ const watchAchievementsWithWine = async () => {
for (const game of games) {
const gameAchievementFiles = findAchievementFiles(game);
const achievementFileInsideDirectory =
findAchievementFileInExecutableDirectory(game);
gameAchievementFiles.push(...achievementFileInsideDirectory);
gameAchievementFiles.push(...(await findAchievementFileInSteamPath(game)));
for (const file of gameAchievementFiles) {
await compareFile(game, file);
@@ -174,10 +177,7 @@ export class AchievementWatcherManager {
const gameAchievementFiles = findAchievementFiles(game);
const achievementFileInsideDirectory =
findAchievementFileInExecutableDirectory(game);
gameAchievementFiles.push(...achievementFileInsideDirectory);
gameAchievementFiles.push(...(await findAchievementFileInSteamPath(game)));
const unlockedAchievements: UnlockedAchievement[] = [];
@@ -259,7 +259,7 @@ export class AchievementWatcherManager {
const gameAchievementFilesMap = findAllAchievementFiles();
return Promise.all(
games.map((game) => {
games.map(async (game) => {
const achievementFiles: AchievementFile[] = [];
for (const objectId of getAlternativeObjectIds(game.objectId)) {
@@ -270,6 +270,10 @@ export class AchievementWatcherManager {
achievementFiles.push(
...findAchievementFileInExecutableDirectory(game)
);
achievementFiles.push(
...(await findAchievementFileInSteamPath(game))
);
}
return { game, achievementFiles };
@@ -284,12 +288,10 @@ export class AchievementWatcherManager {
.then((games) => games.filter((game) => !game.isDeleted));
return Promise.all(
games.map((game) => {
games.map(async (game) => {
const achievementFiles = findAchievementFiles(game);
const achievementFileInsideDirectory =
findAchievementFileInExecutableDirectory(game);
achievementFiles.push(...achievementFileInsideDirectory);
achievementFiles.push(...(await findAchievementFileInSteamPath(game)));
return { game, achievementFiles };
})

View File

@@ -1,9 +1,11 @@
import path from "node:path";
import fs from "node:fs";
import type { Game, AchievementFile } from "@types";
import type { Game, AchievementFile, UserPreferences } from "@types";
import { Cracker } from "@shared";
import { achievementsLogger } from "../logger";
import { SystemPath } from "../system-path";
import { getSteamLocation, getSteamUsersIds } from "../steam";
import { db, levelKeys } from "@main/level";
const getAppDataPath = () => {
if (process.platform === "win32") {
@@ -270,6 +272,51 @@ export const findAchievementFiles = (game: Game) => {
}
}
const achievementFileInsideDirectory =
findAchievementFileInExecutableDirectory(game);
return achievementFiles.concat(achievementFileInsideDirectory);
};
const steamUserIds = await getSteamUsersIds();
const steamPath = await getSteamLocation();
export const findAchievementFileInSteamPath = async (game: Game) => {
if (!steamUserIds.length) {
return [];
}
const userPreferences = await db.get<string, UserPreferences | null>(
levelKeys.userPreferences,
{
valueEncoding: "json",
}
);
if (!userPreferences?.enableSteamAchievements) {
return [];
}
const achievementFiles: AchievementFile[] = [];
for (const steamUserId of steamUserIds) {
const gameAchievementPath = path.join(
steamPath,
"userdata",
steamUserId.toString(),
"config",
"librarycache",
`${game.objectId}.json`
);
if (fs.existsSync(gameAchievementPath)) {
achievementFiles.push({
type: Cracker.Steam,
filePath: gameAchievementPath,
});
}
}
return achievementFiles;
};

View File

@@ -75,6 +75,11 @@ export const parseAchievementFile = (
return processRazor1911(filePath);
}
if (type === Cracker.Steam) {
const parsed = jsonParse(filePath);
return processSteamCacheAchievement(parsed);
}
achievementsLogger.log(
`Unprocessed ${type} achievements found on ${filePath}`
);
@@ -234,6 +239,35 @@ const processGoldberg = (unlockedAchievements: any): UnlockedAchievement[] => {
return newUnlockedAchievements;
};
const processSteamCacheAchievement = (
unlockedAchievements: any[]
): UnlockedAchievement[] => {
const newUnlockedAchievements: UnlockedAchievement[] = [];
const achievementIndex = unlockedAchievements.findIndex(
(element) => element[0] === "achievements"
);
if (achievementIndex === -1) {
achievementsLogger.info("No achievements found in Steam cache file");
return [];
}
const unlockedAchievementsData =
unlockedAchievements[achievementIndex][1]["data"]["vecHighlight"];
for (const achievement of unlockedAchievementsData) {
if (achievement.bAchieved) {
newUnlockedAchievements.push({
name: achievement.strID,
unlockTime: achievement.rtUnlocked * 1000,
});
}
}
return newUnlockedAchievements;
};
const process3DM = (unlockedAchievements: any): UnlockedAchievement[] => {
const newUnlockedAchievements: UnlockedAchievement[] = [];

View File

@@ -9,6 +9,7 @@ import { CloudSync } from "./cloud-sync";
import { logger } from "./logger";
import path from "path";
import { AchievementWatcherManager } from "./achievements/achievement-watcher-manager";
import { MAIN_LOOP_INTERVAL } from "@main/constants";
export const gamesPlaytime = new Map<
string,
@@ -25,7 +26,7 @@ interface GameExecutables {
[key: string]: ExecutableInfo[];
}
const TICKS_TO_UPDATE_API = 120;
const TICKS_TO_UPDATE_API = (3 * 60 * 1000) / MAIN_LOOP_INTERVAL; // 3 minutes
let currentTick = 1;
const platform = process.platform;

View File

@@ -582,7 +582,7 @@ export class WindowManager {
tray.popUpContextMenu(contextMenu);
};
tray.setToolTip("Hydra");
tray.setToolTip("Hydra Launcher");
if (process.platform !== "darwin") {
await updateSystemTray();

View File

@@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hydra</title>
<title>Hydra Launcher</title>
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self' 'unsafe-inline' * data: local:;"

View File

@@ -9,5 +9,16 @@
opacity: 1;
cursor: pointer;
}
&--with-tooltip {
display: flex;
flex-direction: row;
gap: 8px;
align-items: center;
}
&--tooltip {
cursor: pointer;
}
}
}

View File

@@ -5,6 +5,7 @@ import { CheckboxField } from "@renderer/components";
import { useAppSelector } from "@renderer/hooks";
import { settingsContext } from "@renderer/context";
import "./settings-behavior.scss";
import { QuestionIcon } from "@primer/octicons-react";
export function SettingsBehavior() {
const userPreferences = useAppSelector(
@@ -25,6 +26,7 @@ export function SettingsBehavior() {
showHiddenAchievementsDescription: false,
showDownloadSpeedInMegabytes: false,
extractFilesByDefault: true,
enableSteamAchievements: false,
});
const { t } = useTranslation("settings");
@@ -45,6 +47,8 @@ export function SettingsBehavior() {
showDownloadSpeedInMegabytes:
userPreferences.showDownloadSpeedInMegabytes ?? false,
extractFilesByDefault: userPreferences.extractFilesByDefault ?? true,
enableSteamAchievements:
userPreferences.enableSteamAchievements ?? false,
});
}
}, [userPreferences]);
@@ -164,6 +168,25 @@ export function SettingsBehavior() {
})
}
/>
<div className={`settings-behavior__checkbox-container--with-tooltip`}>
<CheckboxField
label={t("enable_steam_achievements")}
checked={form.enableSteamAchievements}
onChange={() =>
handleChange({
enableSteamAchievements: !form.enableSteamAchievements,
})
}
/>
<small
className="settings-behavior__checkbox-container--tooltip"
data-open-article="steam-achievements"
>
<QuestionIcon size={12} />
</small>
</div>
</>
);
}

View File

@@ -35,6 +35,7 @@ export enum Cracker {
onlineFix = "OnlineFix",
goldberg = "Goldberg",
userstats = "user_stats",
Steam = "Steam",
rld = "RLD!",
empress = "EMPRESS",
skidrow = "SKIDROW",

View File

@@ -101,6 +101,7 @@ export interface UserPreferences {
friendStartGameNotificationsEnabled?: boolean;
showDownloadSpeedInMegabytes?: boolean;
extractFilesByDefault?: boolean;
enableSteamAchievements?: boolean;
}
export interface ScreenState {