categories/Gaming.ps1

# Gaming category: Game Mode, Game Bar, background recording, mouse acceleration, HAGS.
# research.md -> gaming category table. Category-level RequiresElevation is $true because
# HAGS needs HKLM, even though the other actions are HKCU-only (category-level, not
# per-action, elevation granularity - consistent with the rest of the project).

function Get-OctaGamingCategory {
    [CmdletBinding()]
    param()
    return [pscustomobject]@{
        Id                          = 'gaming'
        DisplayName                 = 'Gaming'
        Description                 = 'Game Mode, Game Bar, mouse acceleration, HAGS'
        RequiresElevation           = $true
        ContainsIrreversibleActions = $false
        GetActionsFunction          = 'Get-OctaGamingActions'
        ApplyActionFunction         = 'Set-OctaGamingAction'
    }
}

function Get-OctaGamingActions {
    [CmdletBinding()]
    param()
    $actions = @()

    $dwordTargets = @(
        @{ Key = 'HKCU:\Software\Microsoft\GameBar'; Name = 'AutoGameModeEnabled'; Target = 1; Risk = 'Safe' }
        @{ Key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\GameDVR'; Name = 'AppCaptureEnabled'; Target = 0; Risk = 'Safe' }
        @{ Key = 'HKCU:\System\GameConfigStore'; Name = 'GameDVR_Enabled'; Target = 0; Risk = 'Safe' }
    )
    foreach ($t in $dwordTargets) {
        $current = (Get-ItemProperty -Path $t.Key -Name $t.Name -ErrorAction SilentlyContinue).($t.Name)
        if ($null -eq $current -or $current -ne $t.Target) {
            $displayCurrent = if ($null -eq $current) { '(not set)' } else { $current }
            $actions += New-OctaAction -TargetType Registry -TargetIdentifier "$($t.Key)|$($t.Name)" `
                -CurrentValue $displayCurrent -PlannedValue $t.Target -Reversible $true -RiskLevel $t.Risk
        }
    }

    # Mouse acceleration ("enhance pointer precision") - 3 String values, all set to "0" to disable.
    $mouseKey = 'HKCU:\Control Panel\Mouse'
    foreach ($valueName in @('MouseSpeed', 'MouseThreshold1', 'MouseThreshold2')) {
        $current = (Get-ItemProperty -Path $mouseKey -Name $valueName -ErrorAction SilentlyContinue).$valueName
        if ($current -ne '0') {
            $displayCurrent = if ($null -eq $current) { '(not set)' } else { $current }
            $actions += New-OctaAction -TargetType Registry -TargetIdentifier "$mouseKey|$valueName" `
                -CurrentValue $displayCurrent -PlannedValue '0' -Reversible $true -RiskLevel Safe
        }
    }

    # Hardware-accelerated GPU scheduling - HKLM, Moderate (reboot required, occasional driver interactions).
    $hagsKey = 'HKLM:\SOFTWARE\Microsoft\DirectX\GraphicsSettings'
    $currentHags = (Get-ItemProperty -Path $hagsKey -Name 'HwSchMode' -ErrorAction SilentlyContinue).HwSchMode
    if ($null -eq $currentHags -or $currentHags -ne 2) {
        $displayCurrent = if ($null -eq $currentHags) { '(not set)' } else { $currentHags }
        $actions += New-OctaAction -TargetType Registry -TargetIdentifier "$hagsKey|HwSchMode" `
            -CurrentValue $displayCurrent -PlannedValue 2 -Reversible $true -RiskLevel Moderate
    }

    return $actions
}

function Set-OctaGamingAction {
    [CmdletBinding()]
    param([Parameter(Mandatory)]$Action)
    $keyPath, $valueName = $Action.TargetIdentifier -split '\|', 2
    if (-not (Test-Path $keyPath)) {
        New-Item -Path $keyPath -Force | Out-Null
    }
    $type = if ($valueName -like 'Mouse*') { 'String' } else { 'DWord' }
    Set-ItemProperty -Path $keyPath -Name $valueName -Value $Action.PlannedValue -Type $type
}