Skip to content

Commit

Permalink
AutoHDR Sunshine Script Template (#6)
Browse files Browse the repository at this point in the history
Migrates the HDR script over to the new Sunshine Script Installer template and adds a new behavior to fix IDDSampleDriver glitches.
  • Loading branch information
Nonary authored Aug 12, 2024
1 parent e45fce1 commit 6985b42
Show file tree
Hide file tree
Showing 13 changed files with 673 additions and 272 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Releases
assets/*
logs
88 changes: 88 additions & 0 deletions Events.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 = $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
}
95 changes: 0 additions & 95 deletions HDRToggle-Functions.ps1

This file was deleted.

112 changes: 0 additions & 112 deletions HDRToggle.ps1

This file was deleted.

Loading

0 comments on commit 6985b42

Please sign in to comment.