-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAutoHDR.ps1
269 lines (254 loc) · 13.1 KB
/
AutoHDR.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<#
.SYNOPSIS
This script is a powxwershell script created to activate auto HDR on game that do not automatically trigger it.
.DESCRIPTION
This script will created specific registry key that will trigger autoHdr in unsupported Game.
Game should be a DX11/DX12 game.
Registry created will be store under the HKEY_CURRENT_USER\Software\Microsoft\Direct3D
registy value that could be created for each Registry key (game name)
BufferUpgradeOverride (mandatory)
BufferUpgradeEnable10Bit (optional, use it if you have a true 10bits colors monitor/TV)
.EXAMPLE
.\AutoHdr.ps1
Launch the script
1.61 23.07.2024 WPF form resizable
1.6 29.01.2024 Add Tooltips, Add OpenFileDialog
1.5 24.01.2024 Add translation support (psd1 file)
1.4 17.01.2024 Switch remaining Windows forms for WPF.
1.3 10.09.2023 Add Icons in message, bug fix.
1.2 09.09.2023 Add Combobox for removal, label rework
1.1 08.09.2023 Add verification for Removal and uninstall option by security
This will prevent any key or value that were not created by the script to be removed.
1.0 06.09.2023 First version
.LINK
https://github.com/Choum28/AutoHDR
#>
Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName System.Windows.Forms
#load translation if exist, if not found will load en-US one.
Import-LocalizedData -BindingVariable txt
# Define the registry path,
$RegistryPath = "HKCU:\SOFTWARE\Microsoft\Direct3D"
$fail = $false
# Detect game in registry, populate combobox.
function Update-Game {
$C_Listgame.Items.Clear()
if ( Test-Path $RegistryPath ) {
$list = Get-ChildItem $RegistryPath
if ( $list ) {
foreach ( $entry in $list.name ) {
$Game = $entry|split-path -leaf
if ( (Get-Item $RegistryPath\$game).Property -contains "D3DBehaviors" ) {
if ( (Get-Item $RegistryPath\$game).Property -contains "Name" ) {
$C_Listgame.Items.add($game)
}
}
}
}
$C_Listgame.SelectedIndex = $C_Listgame.Items.Count - 1
}
}
#WPF form creation
[xml]$inputXML =@"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Title="AutoHdr" Height="313" Width="497" MinHeight="313" MinWidth="497" ResizeMode="CanResizeWithGrip" Icon="$PSScriptRoot\AutoHdr.ico">
<Viewbox Stretch="Uniform" StretchDirection="UpOnly">
<Grid Margin="0,0,0,0">
<Label Name="L_action" HorizontalAlignment="Left" Margin="27,25,0,0" VerticalAlignment="Top"/>
<RadioButton Name="R_install" HorizontalAlignment="Left" Margin="259,31,0,0" VerticalAlignment="Top"/>
<RadioButton Name="R_remove" HorizontalAlignment="Left" Margin="259,51,0,0" VerticalAlignment="Top"/>
<RadioButton Name="R_uninstall" HorizontalAlignment="Left" Margin="259,71,0,0" VerticalAlignment="Top"/>
<Label Name="T_Nametext" HorizontalAlignment="Left" Margin="33,115,0,0" VerticalAlignment="Top"/>
<Label Name="T_NametextR" HorizontalAlignment="Left" Margin="33,115,0,0" VerticalAlignment="Top"/>
<TextBox Name="T_GameName" HorizontalAlignment="Left" Margin="287,119,0,0" TextWrapping="NoWrap" Text="" VerticalAlignment="Top" Width="150"/>
<TextBlock Name="T_Exetext" HorizontalAlignment="Left" TextWrapping="Wrap" Margin="38,143,0,0" VerticalAlignment="Top" Width="260"/>
<TextBox Name="T_GameExe" HorizontalAlignment="Left" Margin="287,147,0,0" TextWrapping="NoWrap" Text="" VerticalAlignment="Top" Width="150"/>
<Label Name="T_10Bit" HorizontalAlignment="Left" Margin="50,183,0,0" VerticalAlignment="Top"/>
<CheckBox Name="C_10bit" HorizontalAlignment="Left" Margin="287,188,0,0" VerticalAlignment="Top"/>
<Button Name="B_Submit" HorizontalAlignment="Left" Margin="20,230,0,19" VerticalAlignment="Top" RenderTransformOrigin="0.265,0.155"/>
<ComboBox Name="C_Listgame" HorizontalAlignment="Left" Margin="287,119,0,0" VerticalAlignment="Top" Width="150"/>
<Button Name="B_ExePath" Content="..." HorizontalAlignment="Left" Height="19" Margin="440,145,27,0" VerticalAlignment="Top" Width="22"/>
<TextBlock Name="T_URL" HorizontalAlignment="Left" TextWrapping="Wrap" Text="https://github.com/Choum28/AutoHDR" VerticalAlignment="Top" Margin="259,260,0,0" FontSize="8"/>
<TextBlock Name="T_version" HorizontalAlignment="Left" TextWrapping="Wrap" Text="Version 1.7" VerticalAlignment="Top" Margin="429,260,0,0" FontSize="8"/>
</Grid>
</Viewbox>
</Window>
"@
$reader = (New-Object System.Xml.XmlNodeReader $inputXML)
$Window = [Windows.Markup.XamlReader]::Load( $reader )
$inputXML.SelectNodes("//*[@Name]") | Foreach-Object { Set-Variable -Name ($_.Name) -Value $Window.FindName($_.Name)}
$Window.WindowStartupLocation = "CenterScreen"
# Add text to WPF.
$L_action.Content = $txt.main00
$R_install.Content = $txt.mainR1
$R_remove.Content = $txt.mainR2
$R_uninstall.Content = $txt.mainR3
$T_Nametext.Content = $txt.txt1
$T_NametextR.Content = $txt.txtr
$T_Exetext.Text = $txt.txtexe
$T_10Bit.Content = $txt.txt2
$C_10bit.Content = $txt.txtBuff
$C_10bit.Tooltip = $txt.txtBuffTooltip
$T_GameExe.ToolTip = $txt.txtexetooltip
# button, radiobox, text settings and events
$B_ExePath.visibility = "Hidden"
$C_Listgame.visibility = "Hidden"
$T_NametextR.visibility = "Hidden"
$B_Submit.visibility = "Hidden"
$R_install.Add_Checked({
$T_Nametext.visibility = "Visible"
$T_GameName.visibility = "Visible"
$T_Exetext.visibility = "Visible"
$T_GameExe.visibility = "Visible"
$T_10Bit.visibility = "Visible"
$C_10bit.visibility = "Visible"
$C_Listgame.visibility = "Hidden"
$T_NametextR.visibility = "Hidden"
$B_Submit.visibility = "visible"
$B_ExePath.visibility = "visible"
$B_Submit.Content = $txt.ButtonI
})
$R_remove.Add_Checked({
Update-Game
$T_GameExe.Text = ""
$T_Nametext.visibility = "Hidden"
$T_GameName.visibility = "Hidden"
$T_NametextR.visibility = "Visible"
$T_Exetext.visibility = "Hidden"
$T_GameExe.visibility = "Hidden"
$T_10Bit.visibility = "Hidden"
$C_10bit.visibility = "Hidden"
$C_Listgame.visibility = "Visible"
$B_Submit.visibility = "visible"
$B_ExePath.visibility = "Hidden"
$B_Submit.Content = $txt.ButtonR
})
$R_Uninstall.Add_Checked({
$T_GameName.Text = ""
$T_GameExe.Text = ""
$T_Nametext.visibility = "Hidden"
$T_GameName.visibility = "Hidden"
$T_Exetext.visibility = "Hidden"
$T_GameExe.visibility = "Hidden"
$T_10Bit.visibility = "Hidden"
$C_10bit.visibility = "Hidden"
$C_Listgame.visibility = "Hidden"
$T_NametextR.visibility = "Hidden"
$B_Submit.visibility = "visible"
$B_ExePath.visibility = "Hidden"
$B_Submit.Content = $txt.ButtonU
})
$R_install.IsChecked ="$true"
## CLICK ON ICON GAMEPATH (EDIT FORM)
$B_ExePath.add_Click({
$foldername = New-Object System.Windows.Forms.OpenFileDialog
$foldername.Filter = "Executable files (*.exe)|*.exe"
if ( $foldername.ShowDialog() -eq "OK" ) { $T_GameExe.Text = $foldername.FileName }
})
#Code when clicking Ok Button
$B_Submit.Add_Click({
if ( $R_install.IsChecked ) {
# Install action
# test if game name and exe name are present in textbox and valid
# Test if game is already present (to create regkey or not, then String value are created or updated)
if ( [string]::IsNullOrEmpty($T_GameName.Text) ) {
$fail = $true
[System.Windows.MessageBox]::Show($txt.txt1,"",0,48)
}
if ( [string]::IsNullOrEmpty($T_GameExe.Text) ) {
$fail = $true
[System.Windows.MessageBox]::Show($txt.txtexe,"",0,48)
} elseif ( !($T_GameExe.Text -like '*.exe') ) {
$fail = $true
$T_GameExe.Foreground = "Red"
[System.Windows.MessageBox]::Show($txt.exeend,"",0,48)
$T_GameExe.Foreground = "Black"
} elseif ( $T_GameExe.Text.Length -eq 4 ) {
$fail = $true
$T_GameExe.Foreground = "Red"
[System.Windows.MessageBox]::Show($txt.validexe,"",0,48)
$T_GameExe.Foreground = "Black"
}
if ( $fail -eq $false ) {
$Game = $T_GameName.Text
$Name = $T_GameExe.Text
if ( $C_10bit.IsChecked ) { $D3DBehaviors = "BufferUpgradeOverride=1;BufferUpgradeEnable10Bit=1" } else { $D3DBehaviors = "BufferUpgradeOverride=1" }
try {
if ( -not (Test-Path $RegistryPath) ) { New-Item -Path $RegistryPath -Force | Out-Null }
if ( -not (Test-Path $RegistryPath\$Game) ) {
$text = $txt.st1
New-Item $RegistryPath -Name $Game
} else { $text = $txt.st2 }
Set-ItemProperty -Path "$RegistryPath\$Game" -Name "Name" -Value $Name
Set-ItemProperty -Path "$RegistryPath\$Game" -Name "D3DBehaviors" -Value $D3DBehaviors
[System.Windows.MessageBox]::Show("$($Game) -> $($txt.ok1) $($text)","",0,64)
} catch { System.Windows.MessageBox]::Show("$($txt.ko1)`n$($_.Exception.Message)","",0,16) }
}
} elseif ( $R_remove.IsChecked ) {
# remove choice
# test if game is present in registry
# delete key in registry
# Check to not remove different key / value created by other program or manually by user.
if ( [string]::IsNullOrEmpty($C_Listgame.SelectedItem) ) {
$fail = $true
[System.Windows.MessageBox]::Show($txt.Kofound,"",0,64)
} else {
$Game = $C_Listgame.SelectedItem
if ( -not (test-path $RegistryPath\$Game) ) {
$fail = $true
[System.Windows.MessageBox]::Show("$($Game) -> $($koreg)","",0,64)
}
if ( $fail -eq $false ) {
if ( (Get-Item $RegistryPath\$game).Property -contains "D3DBehaviors" ) {
try { Remove-ItemProperty -Path "$RegistryPath\$Game" -Name "D3DBehaviors" } catch { System.Windows.MessageBox]::Show("$($Game) -> $($txt.kodel1)","",0,16) }
}
if ( (Get-Item $RegistryPath\$game).Property -contains "Name" ) {
try { Remove-ItemProperty -Path "$RegistryPath\$Game" -Name "Name" } catch { System.Windows.MessageBox]::Show("$($Game) -> $($txt.kodel2)","",0,16) }
}
if ( (Get-ChildItem $RegistryPath\$game).count -eq 0 ) {
if ( ((Get-Item $RegistryPath\$game).Property).count -eq 0 ){
try { Remove-Item "$RegistryPath\$Game" -r } catch { System.Windows.MessageBox]::Show("$($Game) -> $($txt.kodel3)","",0,16)}
}
}
[System.Windows.MessageBox]::Show("$Game -> $($txt.ok1) $($txt.st3)","",0,64)
Update-Game
}
}
} else {
# Uninstall choice
# check all games in registry
# delete key for each game present
# Check to not remove different key / value created by other program or manually by user.
# Check to remove the main Direct3D key if empty.
if ( Test-Path $RegistryPath ) {
$list = Get-ChildItem $RegistryPath
}
if ( $list ) {
foreach ( $entry in $list.name ) {
$Game = $entry|split-path -leaf
if ( (Get-Item $RegistryPath\$game).Property -contains "D3DBehaviors" ) {
try { Remove-ItemProperty -Path "$RegistryPath\$Game" -Name "D3DBehaviors" } catch { System.Windows.MessageBox]::Show("$($Game) -> $($txt.kodel1)","",0,16) }
}
if ( (Get-Item $RegistryPath\$game).Property -contains "Name" ) {
try { Remove-ItemProperty -Path "$RegistryPath\$Game" -Name "Name" } catch { System.Windows.MessageBox]::Show("$($Game) -> $($txt.kodel2)","",0,16)}
}
if ( (Get-ChildItem $RegistryPath\$game).count -eq 0 ) {
if ( ((Get-Item $RegistryPath\$game).Property).count -eq 0 ) {
try { Remove-Item "$RegistryPath\$Game" -r } catch { System.Windows.MessageBox]::Show("$($Game) -> $($txt.kodel3)","",0,16) }
}
}
[System.Windows.MessageBox]::Show("$($Game) -> $($txt.ok1) $($txt.st3)","",0,64)
}
if ( (Get-ChildItem $RegistryPath).count -eq 0 ) {
if ( ((Get-Item $RegistryPath).Property).count -eq 0 ) {
try { Remove-Item "$RegistryPath" } catch { System.Windows.MessageBox]::Show($txt.kodel14,"",0,16) }
}
}
[System.Windows.MessageBox]::Show($txt.oku,"",0,64)
} else {
[System.Windows.MessageBox]::Show($txt.kou,"",0,64)
}
}
})
# Display forms
$Window.ShowDialog() | out-null