diff --git a/package.json b/package.json index 33aa68f3b..b1e68862c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hyperplay", - "version": "0.17.0", + "version": "0.17.1", "private": true, "main": "build/main/main.js", "homepage": "./", diff --git a/src/backend/launcher.ts b/src/backend/launcher.ts index 7116eec6d..66effa1ea 100644 --- a/src/backend/launcher.ts +++ b/src/backend/launcher.ts @@ -64,6 +64,7 @@ import { LegendaryCommand } from './storeManagers/legendary/commands' import { commandToArgsArray } from './storeManagers/legendary/library' import { searchForExecutableOnPath } from './utils/os/path' import { getHpOverlay } from './overlay' +import { launchingGameShouldOpenOverlay } from './utils/shouldOpenOverlay' async function prepareLaunch( gameSettings: GameSettings, @@ -821,6 +822,8 @@ async function callRunner( return currentPromise } const hpOverlay = await getHpOverlay() + const { shouldOpenOverlay, gameIsEpicForwarderOnHP, hyperPlayListing } = + await launchingGameShouldOpenOverlay(gameInfo) let promise = new Promise((res, rej) => { const child = spawn(bin, commandParts, { @@ -829,13 +832,13 @@ async function callRunner( signal: abortController.signal }) - const shouldOpenOverlay = - gameInfo && - (gameInfo.runner === 'hyperplay' || - (gameInfo.runner === 'sideload' && gameInfo.web3?.supported)) - - if (shouldOpenOverlay) - hpOverlay?.openOverlay(gameInfo?.app_name, gameInfo.runner) + if (gameInfo && shouldOpenOverlay) { + if (gameIsEpicForwarderOnHP && hyperPlayListing?.project_id) { + hpOverlay?.openOverlay(hyperPlayListing?.project_id, gameInfo.runner) + } else { + hpOverlay?.openOverlay(gameInfo?.app_name, gameInfo.runner) + } + } const stdout: string[] = [] const stderr: string[] = [] diff --git a/src/backend/main.ts b/src/backend/main.ts index 25c4a1246..beb840f7a 100644 --- a/src/backend/main.ts +++ b/src/backend/main.ts @@ -184,6 +184,8 @@ import { hrtime } from 'process' import { getHyperPlayReleaseObject } from './storeManagers/hyperplay/utils' import { postPlaySessionTime } from './utils/quests' +import { gameIsEpicForwarderOnHyperPlay } from './utils/shouldOpenOverlay' + async function startProxyServer() { try { const proxyServer = await import('@hyperplay/proxy-server') @@ -1312,10 +1314,18 @@ ipcMain.handle( BigInt(tsStore.get(`${appName}.totalPlayed`, 0)) tsStore.set(`${appName}.totalPlayed`, Number(totalPlaytime)) - postPlaySessionTime( - appName, - parseInt((sessionPlaytimeInMs / BigInt(1000)).toString()) - ) + const { gameIsEpicForwarderOnHP, hyperPlayListing } = + await gameIsEpicForwarderOnHyperPlay(game) + + if (gameIsEpicForwarderOnHP && hyperPlayListing) { + // TODO: fix legendary launch await + postPlaySessionTime(hyperPlayListing.project_id, 900) + } else { + postPlaySessionTime( + appName, + parseInt((sessionPlaytimeInMs / BigInt(1000)).toString()) + ) + } if (runner === 'gog') { await updateGOGPlaytime(appName, startPlayingDate, finishedPlayingDate) diff --git a/src/backend/storeManagers/hyperplay/utils.ts b/src/backend/storeManagers/hyperplay/utils.ts index 7d4fd51a1..1d56fa189 100644 --- a/src/backend/storeManagers/hyperplay/utils.ts +++ b/src/backend/storeManagers/hyperplay/utils.ts @@ -32,6 +32,20 @@ export async function getHyperPlayReleaseMap() { return hpStoreGameMap } +export async function getHyperPlayNameToReleaseMap() { + const hpStoreGameReleases = ( + await axios.get(valistListingsApiUrl) + ).data + + const hpStoreGameMap = new Map() + + hpStoreGameReleases.forEach((val) => { + hpStoreGameMap.set(val.project_name.toLowerCase(), val) + }) + + return hpStoreGameMap +} + /** * @returns an object mapping project id key to listing value * necessary for stringifying over ipc to send to the frontend. diff --git a/src/backend/storeManagers/storeManagerCommon/games.ts b/src/backend/storeManagers/storeManagerCommon/games.ts index bc7544816..f611e9a57 100644 --- a/src/backend/storeManagers/storeManagerCommon/games.ts +++ b/src/backend/storeManagers/storeManagerCommon/games.ts @@ -34,6 +34,7 @@ import { PROVIDERS } from 'common/types/proxy-types' import { getExecutableAndArgs } from 'backend/utils' import { hpApi } from 'backend/utils/hyperplay_api' import { getHpOverlay } from 'backend/overlay' +import { launchingGameShouldOpenOverlay } from 'backend/utils/shouldOpenOverlay' export async function getAppSettings(appName: string): Promise { return ( @@ -360,10 +361,7 @@ export async function launchGame( LogPrefix.Backend ) - const shouldOpenOverlay = - gameInfo && - (gameInfo.runner === 'hyperplay' || - (gameInfo.runner === 'sideload' && gameInfo.web3?.supported)) + const { shouldOpenOverlay } = await launchingGameShouldOpenOverlay(gameInfo) await runWineCommand({ commandParts: [exeOnly, combinedArgs ?? ''], diff --git a/src/backend/utils/shouldOpenOverlay.ts b/src/backend/utils/shouldOpenOverlay.ts new file mode 100644 index 000000000..aa7232f81 --- /dev/null +++ b/src/backend/utils/shouldOpenOverlay.ts @@ -0,0 +1,33 @@ +import { getHyperPlayNameToReleaseMap } from 'backend/storeManagers/hyperplay/utils' +import { GameInfo } from 'common/types' + +export async function gameIsEpicForwarderOnHyperPlay(gameInfo: GameInfo) { + const gameNameMap = await getHyperPlayNameToReleaseMap() + let hyperPlayListing = undefined + const gameInfoTitle = gameInfo.title.toLowerCase() + const gameIsEpicForwarderOnHP = + gameInfo.runner === 'legendary' && gameNameMap.has(gameInfoTitle) + if (gameIsEpicForwarderOnHP) { + hyperPlayListing = gameNameMap.get(gameInfoTitle) + } + return { gameIsEpicForwarderOnHP, hyperPlayListing } +} + +export async function launchingGameShouldOpenOverlay(gameInfo?: GameInfo) { + if (!gameInfo) { + return { shouldOpenOverlay: false } + } + const { gameIsEpicForwarderOnHP, hyperPlayListing } = + await gameIsEpicForwarderOnHyperPlay(gameInfo) + const gameIsDirectOnHyperPlay = gameInfo.runner === 'hyperplay' + const gameIsSideloadedWithWeb3 = + gameInfo.runner === 'sideload' && !!gameInfo.web3?.supported + return { + shouldOpenOverlay: + gameIsEpicForwarderOnHP || + gameIsDirectOnHyperPlay || + gameIsSideloadedWithWeb3, + gameIsEpicForwarderOnHP, + hyperPlayListing + } +}