-
Notifications
You must be signed in to change notification settings - Fork 1
/
Events.ps1
88 lines (71 loc) · 2.85 KB
/
Events.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Determine the path of the currently running script and set the working directory to that path
param(
[Parameter(Position = 0, Mandatory = $true)]
[Alias("n")]
[string]$scriptName
)
$path = (Split-Path $MyInvocation.MyCommand.Path -Parent)
Set-Location $path
. .\Helpers.ps1 -n $scriptName
# Load settings from a JSON file located in the same directory as the script
$settings = Get-Settings
# Initialize a script scoped dictionary to store variables.
# This dictionary is used to pass parameters to functions that might not have direct access to script scope, like background jobs.
if (-not $script:arguments) {
$script:arguments = @{}
}
$dllPath = "$($PWD.Path)\HDRController.dll".Replace("\", "\\")
# Define the function signature
Add-Type -TypeDefinition @"
using System.Runtime.InteropServices;
public static class HDRController {
[DllImport("$dllPath", EntryPoint = "GetGlobalHDRState")]
public static extern bool GetGlobalHDRState();
[DllImport("$dllPath", EntryPoint = "EnableGlobalHDRState")]
public static extern void EnableGlobalHDRState();
[DllImport("$dllPath", EntryPoint = "DisableGlobalHDRState")]
public static extern void DisableGlobalHDRState();
}
"@
# Function to execute at the start of a stream
function OnStreamStart() {
$hostHDR = [HDRController]::GetGlobalHDRState()
$script:arguments.Add("hostHDR", $hostHDR)
$clientHdrState = [System.Boolean]::Parse($env:SUNSHINE_CLIENT_HDR)
Write-Host "Current (Host) HDR State: $hostHDR"
Write-Host "Current (Client) HDR State: $clientHdrState"
if ($hostHDR -ne $clientHdrState) {
if ($clientHdrState) {
Write-Host "Enabling HDR"
[HDRController]::EnableGlobalHDRState()
}
else {
Write-Host "Turning off HDR"
[HDRController]::DisableGlobalHDRState()
}
}
if($settings.IDDSampleFix){
if([HDRController]::GetGlobalHDRState() -and $clientHdrState){
Write-Host "IDDSample Fix is enabled, now automating turning HDR off and on again."
[HDRController]::DisableGlobalHDRState()
[HDRController]::EnableGlobalHDRState()
Write-Host "HDR has been toggled successfully!"
}
}
elseif($hostHDR -eq $clientHdrState) {
Write-Host "Client already matches the host for HDR, no changes will be applied."
}
}
# Function to execute at the end of a stream. This function is called in a background job,
# and hence doesn't have direct access to the script scope. $kwargs is passed explicitly to emulate script:arguments.
function OnStreamEnd($kwargs) {
if ($kwargs["hostHDR"]) {
Write-Host "Enabling HDR"
[HDRController]::EnableGlobalHDRState()
}
else {
Write-Host "Turning off HDR"
[HDRController]::DisableGlobalHDRState()
}
return $true
}