Skip to content

Enhancements to input validation, registry management, and documentation #1

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 53 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,53 @@
# autohdr-powershell-script
Enables windows 11 AutoHDR for non compatible games.
# Update registry to enable AutoHDR for games on Windows 11

This PowerShell script assists users in enabling Windows 11's AutoHDR feature for games that are not officially supported. It facilitates the management of Direct3D registry entries, allowing you to install, remove, or list registry entries related to AutoHDR settings.

## Description

The script aims to enhance your gaming experience on Windows 11 by enabling the AutoHDR feature for games that lack official support. Here is how it achieves this:

### Registry keys and values

The script modifies the Windows registry to manage the Direct3D settings for specific executable files. Here are the main components it interacts with:

- **Main registry path**: The script uses the registry path `HKCU:\SOFTWARE\Microsoft\Direct3D`, storing the Direct3D settings for different executables here.

- **D3DBehaviors**: This registry key is crucial in enabling AutoHDR as it defines the behaviors for Direct3D. Users can choose between two settings:
- `BufferUpgradeOverride=1`: This setting is a general buffer upgrade override.
- `BufferUpgradeOverride=1;BufferUpgradeEnable10Bit=1`: Along with buffer upgrade override, this setting enables 10-bit buffer support.

These settings enable the AutoHDR feature for non-compatible games by overriding default buffer settings to ones compatible with AutoHDR.

- **Executable Name**: Users specify the executable file name for which the settings should be applied. This is stored as a new registry entry under the main registry path with the properties `Name` and `D3DBehaviors` defined to store the executable name and chosen Direct3D behaviors, respectively.

### Workflow

1. **Initialization**: The script initially verifies the existence of the main registry path, creating it if absent.
2. **Action selection**: Users are prompted to select an action — install, remove, or list entries, or exit the script.
3. **Details specification**: Depending on the chosen action, users may be required to specify details like the executable name or desired Direct3DBehaviors settings.

## Installation

To set up the script:

1. Ensure PowerShell is installed on your Windows 11 system.
2. Download the PowerShell script file from this repository.
3. Run it in a PowerShell environment with the required privileges to modify the registry entries.

## Usage

Execute the script in a PowerShell environment and adhere to the on-screen instructions to manage Direct3D registry entries effectively. Use the following command to run the script:

```sh
powershell -NoProfile -ExecutionPolicy Bypass -File "Path/To/Your/Script.ps1"
```

Replace `"Path/To/Your/Script.ps1"` with the actual path to your script.

## Contribution

Contributions are welcomed. Feel free to fork the repository and submit pull requests. Ensure to maintain the established coding style and conventions.

## License

[MIT License](LICENSE)
182 changes: 142 additions & 40 deletions autohdr.ps1
Original file line number Diff line number Diff line change
@@ -1,47 +1,149 @@
# Prompt the user to choose whether to install or remove entries
$Action = Read-Host "Do you want to install or remove entries? (i/r)"

if ($Action -eq "i") {
# Prompt the user for the "Name" value
$Name = Read-Host "Enter the name of the .exe (e.g., Starfield.exe)"

# Display options for "D3DBehaviors"
Write-Host "Choose an option for D3DBehaviors:"
Write-Host "1. BufferUpgradeOverride=1"
Write-Host "2. BufferUpgradeOverride=1;BufferUpgradeEnable10Bit=1"

# Prompt the user for their choice
$Choice = Read-Host "Enter the number corresponding to your choice"

# Validate the user's choice for "D3DBehaviors"
if ($Choice -eq "1") {
$D3DBehaviors = "BufferUpgradeOverride=1"
} elseif ($Choice -eq "2") {
$D3DBehaviors = "BufferUpgradeOverride=1;BufferUpgradeEnable10Bit=1"
} else {
Write-Host "Invalid choice. Please enter 1 or 2 for the D3DBehaviors option."
exit
}
<#
.SYNOPSIS
This script manages Direct3D registry entries for various executable files, allowing the user to install, remove, or list registry entries.
.DESCRIPTION
The script facilitates the management of Direct3D registry settings by:
- Creating the main registry path if it does not exist
- Prompting users to install new settings, remove existing ones, or list all current entries
.EXAMPLE
Run the script and follow the on-screen prompts to manage Direct3D registry entries.
#>

# Define the main registry path
$MainRegistryPath = "HKCU:\SOFTWARE\Microsoft\Direct3D"

# Check if the main registry path exists, if not create it
if (-not (Test-Path -Path $MainRegistryPath)) {
New-Item -Path $MainRegistryPath -Force
}

Function Get-Action {
# Prompt the user to choose whether to install, remove, or list entries
do {
$Action = Read-Host "Do you want to install, remove, or list entries, or exit? (i/r/l/x)"
if ($Action -eq 'x') {
Write-Host "Exiting script..."
exit
}
} while ($Action -ne 'i' -and $Action -ne 'r' -and $Action -ne 'l')

return $Action
}

# Define the registry path
$RegistryPath = "HKCU:\SOFTWARE\Microsoft\Direct3D"
Function Get-D3DBehaviors {
# Display options for "D3DBehaviors" and get user choice
do {
Write-Host "Choose an option for D3DBehaviors:"
Write-Host "1. BufferUpgradeOverride=1"
Write-Host "2. BufferUpgradeOverride=1;BufferUpgradeEnable10Bit=1"
$Choice = Read-Host "Enter the number corresponding to your choice, or enter 'x' to exit"

if ($Choice -eq "1") {
$D3DBehaviors = "BufferUpgradeOverride=1"
}
elseif ($Choice -eq "2") {
$D3DBehaviors = "BufferUpgradeOverride=1;BufferUpgradeEnable10Bit=1"
}
elseif ($Choice -eq 'x') {
Write-Host "Exiting script..."
exit
}
else {
Write-Host "Invalid choice. Please enter 1, 2 or 'x' to exit."
}
} while ($Choice -ne '1' -and $Choice -ne '2')

return $D3DBehaviors
}

Function Perform-Action {
param (
[string]$Action
)

if ($Action -eq "i") {
$Name = Read-Host "Enter the name of the .exe (e.g., Starfield.exe), or enter 'x' to exit"
if ($Name -eq 'x') {
Write-Host "Exiting script..."
exit
}
$D3DBehaviors = Get-D3DBehaviors
$RegistryPath = Join-Path -Path $MainRegistryPath -ChildPath $Name

if (-not (Test-Path -Path $RegistryPath)) {
New-Item -Path $RegistryPath -Force
}
Set-ItemProperty -Path $RegistryPath -Name "Name" -Value $Name
Set-ItemProperty -Path $RegistryPath -Name "D3DBehaviors" -Value $D3DBehaviors

# Set the "Name" and "D3DBehaviors" values in the registry
Set-ItemProperty -Path $RegistryPath -Name "Name" -Value $Name
Set-ItemProperty -Path $RegistryPath -Name "D3DBehaviors" -Value $D3DBehaviors
Write-Host "Registry values installed."

}
elseif ($Action -eq "r") {
$SubKeys = Get-ChildItem -Path $MainRegistryPath

Write-Host "Registry values installed."
} elseif ($Action -eq "r") {
# Define the registry path
$RegistryPath = "HKCU:\SOFTWARE\Microsoft\Direct3D"
if ($SubKeys.Count -eq 0) {
Write-Host "No entries found."
}
else {
$Index = 1
foreach ($SubKey in $SubKeys) {
$SubKeyDetail = Get-Item -LiteralPath $SubKey.PSPath
Write-Host "$Index. $($SubKeyDetail.Name -replace '.*\\', '')"
$SubKeys[$Index - 1] = $SubKeyDetail
$Index++
}

# Remove the entries
Remove-ItemProperty -Path $RegistryPath -Name "Name" -ErrorAction SilentlyContinue
Remove-ItemProperty -Path $RegistryPath -Name "D3DBehaviors" -ErrorAction SilentlyContinue
$Choice = Read-Host "Enter the number corresponding to the entry you wish to remove, or enter 'all' to remove all entries, or enter 'x' to exit"

if ($Choice -eq 'x') {
Write-Host "Exiting script..."
exit
}
elseif ($Choice -eq 'all') {
$Confirm = Read-Host "Are you sure you want to remove all entries? (y/n/x)"
if ($Confirm -eq 'x') {
Write-Host "Exiting script..."
exit
}
elseif ($Confirm -eq 'y') {
Remove-Item -Path $MainRegistryPath -Recurse -Force
New-Item -Path $MainRegistryPath -Force
Write-Host "All entries removed."
}
}
else {
if ($Choice -match '^\d+$' -and [int]$Choice -ge 1 -and [int]$Choice -le $SubKeys.Count) {
$SelectedSubKey = $SubKeys[[int]$Choice - 1]
Remove-Item -Path $SelectedSubKey.PSPath -Force
Write-Host "Entry removed."
}
else {
Write-Host "Invalid choice. No entries were removed."
}
}
}

Write-Host "Registry entries removed."
} else {
Write-Host "Invalid action. Please enter 'i' for install or 'r' for remove."

}
elseif ($Action -eq "l") {
$SubKeys = Get-ChildItem -Path $MainRegistryPath

if ($SubKeys.Count -eq 0) {
Write-Host "No entries found."
}
else {
foreach ($SubKey in $SubKeys) {
Write-Host "$($SubKey.Name -replace '.*\\', '')"
}
}
}
}

Write-Host "Script completed."
do {
# Get the initial action from the user
$Action = Get-Action

# Perform the initial action
Perform-Action -Action $Action
} while ($true)