Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions files/shellscripts/EpicGamesLauncher.ps1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this would break the epic parser on OS X as it currently stands; it will have to be updated to use the previous handling or have a separate shell script for os x.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I was afraid of but couldn't test. I'll probably see about falling back to not using the script on non-windows computers as I don't have an OS X machine to test on currently

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cbartondock I put in a check so that it fallbacks to the original launchOptions when not windows. I also ended up making changes to the powershell file itself so that it closes everything properly if you close the game from steam

Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
Param(
[Parameter(Mandatory=$true)]
[string]$gameURI,
[Parameter(Mandatory=$true)]
[string]$gameProcessName,
[int]$parentPid = 0
)

function Wait-ForGameStart([switch]$CheckParent) {
$launchTimeout = 120
$elapsed = 0
while (-not (Get-Process -Name $gameProcessName -ErrorAction SilentlyContinue) -and ($elapsed -lt $launchTimeout)) {
if ($CheckParent -and -not (Test-ParentAlive)) {
break
}
Start-Sleep -Seconds 1
$elapsed += 1
}
return [bool](Get-Process -Name $gameProcessName -ErrorAction SilentlyContinue)
}

# --- Detached Child / Watcher Mode ---
if ($parentPid -ne 0) {
$parentProcess = $null

try {
$proc = [System.Diagnostics.Process]::GetProcessById($parentPid)
if ($proc.ProcessName -match '^powershell|^pwsh') {
$parentProcess = $proc
}
} catch {
$parentProcess = $null
}

function Test-ParentAlive {
if ($null -eq $parentProcess) { return $false }
try {
$parentProcess.Refresh()
return (-not $parentProcess.HasExited)
} catch {
return $false
}
}

$launchTimeout = 120
$elapsed = 0

$gameStarted = Wait-ForGameStart -CheckParent

# Wait for either the game or parent process to exit
while ((Test-ParentAlive) -and (Get-Process -Name $gameProcessName -ErrorAction SilentlyContinue)) {
Start-Sleep -Seconds 1
}

# Stop the game if it's still running
if (Get-Process -Name $gameProcessName -ErrorAction SilentlyContinue) {
Stop-Process -Name $gameProcessName -Force -ErrorAction SilentlyContinue
}

# Stop the parent process if it's still running
try {
$parentProcess.Refresh()
if (-not $parentProcess.HasExited) {
$parentProcess.Kill()
}
} catch {}

# Only give the Epic Games Launcher time to finish cloud save sync if the game actually started
if ($gameStarted) {
Start-Sleep -Seconds 10
} else {
Start-Sleep -Seconds 2
}

Stop-Process -Name "EpicGamesLauncher" -Force -ErrorAction SilentlyContinue

exit 0
}

# --- Parent / Launcher Mode ---

# Launch the detached watcher child process
$watcherArgs = "-WindowStyle Hidden -NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" -gameURI `"$gameURI`" -gameProcessName `"$gameProcessName`" -parentPid $PID"
Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{
CommandLine = "powershell.exe $watcherArgs"
}

Start-Process $gameURI

Wait-ForGameStart

# Wait for the game to exit
while (Get-Process -Name $gameProcessName -ErrorAction SilentlyContinue) {
Start-Sleep -Seconds 1
}

exit 0
13 changes: 10 additions & 3 deletions src/lib/parsers/epic.parser.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ParserInfo, GenericParser, ParsedData } from "../../models";
import { ParserInfo, GenericParser, ParsedData, EpicGameManifest } from "../../models";
import { APP } from "../../variables";
import * as _ from "lodash";
import * as fs from "fs-extra";
import * as os from "os";
import * as path from "path";
import { glob } from "glob";
import * as paths from "../../paths";

export class EpicParser implements GenericParser {
private get lang() {
Expand Down Expand Up @@ -65,9 +66,10 @@ export class EpicParser implements GenericParser {
const files: string[] = await glob(
[epicManifestsDir.replace(/\\/g, "/"), "*.item"].join("/"),
);
const scriptsPath = path.join(paths.userDataDir, "scripts");
for (let file of files) {
if (fs.existsSync(file) && fs.lstatSync(file).isFile()) {
let item = JSON.parse(fs.readFileSync(file).toString());
let item: EpicGameManifest = JSON.parse(fs.readFileSync(file).toString());
let launchPath = path.join(
item.InstallLocation,
item.LaunchExecutable,
Expand All @@ -77,13 +79,18 @@ export class EpicParser implements GenericParser {
fs.existsSync(launchPath) &&
!appTitles.includes(item.DisplayName)
) {
const processName = path.parse(item.LaunchExecutable).name;
const launchOptions = os.type() == "Windows_NT"
? `-windowStyle hidden -NoProfile -ExecutionPolicy Bypass -File .\\EpicGamesLauncher.ps1 -gameURI "com.epicgames.launcher://apps/${item.AppName}?action=launch&silent=true" -gameProcessName "${processName}"`
: `-windowStyle hidden -NoProfile -ExecutionPolicy Bypass -Command "&Start-Process \\"com.epicgames.launcher://apps/${item.AppName}?action=launch&silent=true\\""`;
appTitles.push(item.DisplayName);
parsedData.success.push({
extractedTitle: item.DisplayName,
extractedAppId: item.AppName,
launchOptions: `-windowStyle hidden -NoProfile -ExecutionPolicy Bypass -Command "&Start-Process \\"com.epicgames.launcher://apps/${item.AppName}?action=launch&silent=true\\""`,
launchOptions,
filePath: launchPath,
fileLaunchOptions: item.LaunchCommand,
...(os.type() == "Windows_NT" ? { startInDirectory: scriptsPath } : undefined),
});
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/models/epic.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// game json manifest
export interface EpicGameManifest {
InstallLocation: string;
LaunchExecutable: string;
DisplayName: string;
AppName: string;
LaunchCommand: string;
}
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export * from "./user-exceptions.model";
export * from "./config-presets.model";
export * from "./error.model";
export * from "./uwp.model";
export * from "./epic.model";
Loading