Repository navigation
Expand file tree
/
Copy pathlaunch.ps1
More file actions
55 lines (55 loc) · 4.43 KB
/
Copy pathlaunch.ps1
File metadata and controls
55 lines (55 loc) · 4.43 KB
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
param([string]$GameDirectory='',[switch]$VerifyOnly)
$ErrorActionPreference='Stop'
$lastPath=Join-Path $PSScriptRoot 'work/last-install.json'
if(!(Test-Path -LiteralPath $lastPath)){throw 'Run Install Hitman VR.cmd first, and keep this extracted mod folder in place.'}
$last=Get-Content -LiteralPath $lastPath -Raw | ConvertFrom-Json
$m=Get-Content -LiteralPath $last.Manifest -Raw | ConvertFrom-Json
if(!$GameDirectory){$retail=[IO.Path]::GetFullPath($m.Retail)}else{
$selected=[IO.Path]::GetFullPath($GameDirectory.Trim().Trim('"'))
$retail=if(Test-Path -LiteralPath (Join-Path $selected 'HMA.exe')){$selected}else{[IO.Path]::GetFullPath((Join-Path $selected 'retail'))}
}
$exe=Join-Path $retail 'HMA.exe'
if((Get-FileHash -LiteralPath $exe -Algorithm SHA256).Hash -ne '5B93E0060C100197F658B7FC9D2F39323E3148396F7DE7CFF4496AAF4029952D'){throw 'Unsupported HMA.exe.'}
if(Get-Process HMA -ErrorAction SilentlyContinue | Where-Object Path -eq $exe){throw 'Hitman is already running. Close it before launching the VR test.'}
if($m.Retail -ne $retail){throw 'This game folder does not match the installed test.'}
foreach($item in $m.Files){
# The INI is a user preference file, including the optional GI-off workaround.
if($item.Relative -eq 'HitmanAbsolutionVR.ini'){continue}
if((Get-FileHash -LiteralPath (Join-Path $retail $item.Relative) -Algorithm SHA256).Hash -ne $item.InstalledSHA256){throw "Installed payload changed: $($item.Relative)"}
}
if($VerifyOnly){Write-Output 'Installed binaries verified. User INI preferences may be edited.';return}
$ini=Get-Content -LiteralPath (Join-Path $retail 'HitmanAbsolutionVR.ini') -Raw
$useHeadsetResolution=!( $ini -match '(?im)^\s*UseHeadsetResolution\s*=\s*0\s*(?:;.*)?$' )
$registry='HKCU:\Software\IO Interactive\Hitman Absolution'
$displayBackup=$null
$oldEnvironment=@{}
try {
if($useHeadsetResolution){
$query=& (Join-Path $retail 'HitmanAbsolutionVR/HitmanAbsolutionVRHost.exe') --display-query
if($LASTEXITCODE -ne 0){throw 'Could not query the headset resolution. Start the headset runtime, or set UseHeadsetResolution=0 in the INI.'}
$display=$query | ConvertFrom-Json
if($display.width -lt 1 -or $display.width -gt 16384 -or $display.height -lt 1 -or $display.height -gt 8192){throw 'Headset recommended resolution is outside the native transport limits.'}
$environment=@{HITMAN_VR_EYE_WIDTH=[string]$display.width;HITMAN_VR_EYE_HEIGHT=[string]$display.height;HITMAN_VR_REFRESH_HZ=$display.refreshHz.ToString([Globalization.CultureInfo]::InvariantCulture)}
foreach($name in $environment.Keys){$oldEnvironment[$name]=[Environment]::GetEnvironmentVariable($name,'Process');[Environment]::SetEnvironmentVariable($name,$environment[$name],'Process')}
$values=@{ResolutionWidth=[int]$display.width;ResolutionHeight=[int]$display.height;Refreshrate=[int][Math]::Round($display.refreshHz);Fullscreen=1;ExclusiveFullscreen=1;VSync=0;WindowWidth=[int]$display.width;WindowHeight=[int]$display.height;Aspectratio=0}
$saved=Get-ItemProperty -LiteralPath $registry
$displayBackup=@()
foreach($name in $values.Keys){$value=$saved.PSObject.Properties[$name];$displayBackup+=@{Name=$name;Existed=($null -ne $value);Value=if($value){$value.Value}else{$null};Applied=$values[$name]}}
$backupDirectory=Join-Path $PSScriptRoot 'work/display-settings'
New-Item -ItemType Directory -Force -Path $backupDirectory | Out-Null
$displayBackup | ConvertTo-Json | Set-Content -LiteralPath (Join-Path $backupDirectory ((Get-Date -Format 'yyyyMMdd-HHmmss-fff')+'.json'))
foreach($name in $values.Keys){New-ItemProperty -LiteralPath $registry -Name $name -PropertyType DWord -Value $values[$name] -Force | Out-Null}
Write-Output "Native headset render size: $($display.width)x$($display.height) per eye."
}
$game=Start-Process -FilePath $exe -WorkingDirectory $retail -PassThru
$game.WaitForExit()
} finally {
foreach($item in $displayBackup){
$now=Get-ItemPropertyValue -LiteralPath $registry -Name $item.Name -ErrorAction SilentlyContinue
if($now -eq $item.Applied){
if($item.Existed){New-ItemProperty -LiteralPath $registry -Name $item.Name -PropertyType DWord -Value $item.Value -Force | Out-Null}
else{Remove-ItemProperty -LiteralPath $registry -Name $item.Name}
}
}
foreach($name in $oldEnvironment.Keys){[Environment]::SetEnvironmentVariable($name,$oldEnvironment[$name],'Process')}
}