-
-
Notifications
You must be signed in to change notification settings - Fork 152
Auto close epic games #748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lexarvn
wants to merge
2
commits into
SteamGridDB:master
Choose a base branch
from
lexarvn:epic-auto-close
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
launchOptionswhen 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