# ============================================================================ # RMS TECH - OBS BOOST / Otimizacao para o OBS Studio # Interface + logica · by @rms.tech · distribuicao gratuita / free to share # Executado pelo RMS-TECH-OBS-BOOST.bat (nao rode este .ps1 direto). # ============================================================================ $ErrorActionPreference = 'Stop' # --- pasta do script / script folder ------------------------------------ $ScriptDir = $PSScriptRoot if (-not $ScriptDir) { $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path } try { Set-Location -LiteralPath $ScriptDir } catch {} try { [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 } catch {} # --- liga cores ANSI 24-bit no console classico / enable truecolor ----- if (-not $env:WT_SESSION) { try { Add-Type -Namespace RmsVT -Name Native -MemberDefinition '[DllImport("kernel32.dll")] public static extern IntPtr GetStdHandle(int h); [DllImport("kernel32.dll")] public static extern bool GetConsoleMode(IntPtr h, out uint m); [DllImport("kernel32.dll")] public static extern bool SetConsoleMode(IntPtr h, uint m);' $hOut = [RmsVT.Native]::GetStdHandle(-11) $cmode = [uint32]0 [void][RmsVT.Native]::GetConsoleMode($hOut, [ref]$cmode) [void][RmsVT.Native]::SetConsoleMode($hOut, $cmode -bor 0x0004) } catch {} } # --- tamanho da janela / window size (best effort) -------------------- try { $ui = $Host.UI.RawUI $mx = $ui.MaxPhysicalWindowSize $cols = [Math]::Min(104, [int]$mx.Width) $rws = [Math]::Min(46, [int]$mx.Height) $bs = $ui.BufferSize; if ($bs.Width -lt $cols) { $bs.Width = $cols }; $bs.Height = 3000; $ui.BufferSize = $bs $ws = $ui.WindowSize; $ws.Width = $cols; $ws.Height = $rws; $ui.WindowSize = $ws } catch {} # --- paleta / palette -------------------------------------------------- $ESC = [char]27 $RS = "$ESC[0m" $BLD = "$ESC[1m" function fg ($r, $g, $b) { "$ESC[38;2;$r;$g;${b}m" } function bgc ($r, $g, $b) { "$ESC[48;2;$r;$g;${b}m" } $CY = fg 90 210 255 $MG = fg 200 100 255 $GR = fg 90 230 150 $RD = fg 255 100 115 $YL = fg 255 205 100 $DM = fg 120 126 145 $WH = fg 236 239 246 $TX = fg 205 210 226 $DOT = [char]183 $PTR = [char]187 $AUP = [char]24 $ADN = [char]25 # --- banner (fonte ANSI Shadow, chars CP437-safe) ------------------- $RMS = @( '██████╗ ███╗ ███╗███████╗', '██╔══██╗████╗ ████║██╔════╝', '██████╔╝██╔████╔██║███████╗', '██╔══██╗██║╚██╔╝██║╚════██║', '██║ ██║██║ ╚═╝ ██║███████║', '╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝') $TECH = @( '████████╗███████╗ ██████╗██╗ ██╗', '╚══██╔══╝██╔════╝██╔════╝██║ ██║', ' ██║ █████╗ ██║ ███████║', ' ██║ ██╔══╝ ██║ ██╔══██║', ' ██║ ███████╗╚██████╗██║ ██║', ' ╚═╝ ╚══════╝ ╚═════╝╚═╝ ╚═╝') function GradBlock ($arr, $c1, $c2, $ind) { $n = $arr.Count for ($i = 0; $i -lt $n; $i++) { if ($n -le 1) { $q = 0 } else { $q = $i / ($n - 1) } $cr = [int]($c1[0] + ($c2[0] - $c1[0]) * $q) $cg = [int]($c1[1] + ($c2[1] - $c1[1]) * $q) $cb = [int]($c1[2] + ($c2[2] - $c1[2]) * $q) Write-Host ((' ' * $ind) + (fg $cr $cg $cb) + $arr[$i] + $RS) } } function Header { try { Clear-Host } catch {} Write-Host '' GradBlock $RMS @(95, 215, 255) @(150, 130, 255) 6 GradBlock $TECH @(150, 130, 255) @(210, 95, 255) 6 Write-Host '' Write-Host (' ' + $DM + ('─' * 58) + $RS) Write-Host (' ' + $WH + $BLD + 'OBS BOOST' + $RS + $DM + " Otimizacao para OBS Studio $DOT OBS Studio Optimization" + $RS) Write-Host (' ' + $DM + 'by ' + $RS + $MG + $BLD + '@rms.tech' + $RS + $DM + " $DOT distribuicao gratuita" + $RS) Write-Host '' } # --- menu com setas / arrow-key menu ------------------------------- function Menu ($items, $title) { $sel = 0 $w = 58 while ($true) { Header if ($title) { Write-Host (' ' + $YL + $title + $RS); Write-Host '' } Write-Host (' ' + $DM + '┌' + ('─' * $w) + '┐' + $RS) Write-Host (' ' + $DM + '│' + (' ' * $w) + '│' + $RS) for ($i = 0; $i -lt $items.Count; $i++) { $lab = ' ' + $items[$i].Key + ' ' + $items[$i].Text if ($i -eq $sel) { $cell = ' ' + $PTR + ' ' + $lab $cell = $cell + (' ' * [Math]::Max(0, $w - $cell.Length)) Write-Host (' ' + $DM + '│' + $RS + (bgc 38 44 62) + (fg 130 232 255) + $BLD + $cell + $RS + $DM + '│' + $RS) } else { $cell = ' ' + $lab $cell = $cell + (' ' * [Math]::Max(0, $w - $cell.Length)) Write-Host (' ' + $DM + '│' + $RS + $TX + $cell + $RS + $DM + '│' + $RS) } } Write-Host (' ' + $DM + '│' + (' ' * $w) + '│' + $RS) Write-Host (' ' + $DM + '└' + ('─' * $w) + '┘' + $RS) Write-Host '' Write-Host (' ' + $DM + "$AUP $ADN" + $RS + $TX + ' navegar ' + $RS + $DM + 'Enter' + $RS + $TX + ' confirmar ' + $RS + $DM + 'Esc' + $RS + $TX + ' voltar' + $RS) $k = [Console]::ReadKey($true) if ($k.Key -eq 'UpArrow') { $sel = ($sel - 1 + $items.Count) % $items.Count; continue } if ($k.Key -eq 'DownArrow') { $sel = ($sel + 1) % $items.Count; continue } if ($k.Key -eq 'Enter') { return $items[$sel].Id } if ($k.Key -eq 'Escape') { return 'BACK' } foreach ($it in $items) { if ($it.Key -ne '' -and ([string]$k.KeyChar -eq [string]$it.Key)) { return $it.Id } } } } # --- helpers de status / status helpers --------------------------- function SLine ($txt) { Write-Host (' ' + $DM + ' ... ' + $RS + $TX + $txt + $RS) -NoNewline } function SOk ($txt) { Write-Host ("`r" + $ESC + '[2K' + ' ' + (bgc 30 90 55) + $GR + $BLD + ' OK ' + $RS + ' ' + $TX + $txt + $RS) } function SFail ($txt) { Write-Host ("`r" + $ESC + '[2K' + ' ' + (bgc 100 35 40) + $RD + $BLD + ' ERRO ' + $RS + ' ' + $TX + $txt + $RS) } function SWarn ($txt) { Write-Host ("`r" + $ESC + '[2K' + ' ' + (bgc 95 75 20) + $YL + $BLD + ' AVISO ' + $RS + ' ' + $TX + $txt + $RS) } function Bar ($total, $done) { $wd = 34 if ($total -le 0) { $f = 0 } else { $f = [int][Math]::Round($wd * $done / $total) } ' ' + $CY + ('█' * $f) + $DM + ('░' * ($wd - $f)) + $RS + $TX + (' {0}/{1}' -f $done, $total) + $RS } function GBox ($lines, $col) { $lines = @($lines) $w = 50 Write-Host (' ' + $col + $BLD + '╔' + ('═' * $w) + '╗' + $RS) foreach ($l in $lines) { $s = ' ' + $l if ($s.Length -gt $w) { $s = $s.Substring(0, $w) } $s = $s + (' ' * ($w - $s.Length)) Write-Host (' ' + $col + $BLD + '║' + $s + '║' + $RS) } Write-Host (' ' + $col + $BLD + '╚' + ('═' * $w) + '╝' + $RS) } function Pause2 { Write-Host '' Write-Host (' ' + $DM + 'pressione qualquer tecla para voltar ao menu...' + $RS) [void][Console]::ReadKey($true) } # --- executa reg.exe silencioso / run reg.exe quietly ------------ function RegRun { param([Parameter(ValueFromRemainingArguments = $true)] $a) $old = $ErrorActionPreference $ErrorActionPreference = 'SilentlyContinue' try { $null = & reg @a 2>&1 } catch {} $ok = ($LASTEXITCODE -eq 0) $ErrorActionPreference = $old return $ok } # --- caminhos do OBS / OBS paths --------------------------------------- $IFEO = 'HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options' $IFEO_OBS = "$IFEO\obs64.exe" $GPUPREF_K = 'HKCU\Software\Microsoft\DirectX\UserGpuPreferences' # acha o obs64.exe instalado (para o ajuste de GPU) / find installed obs64.exe function FindObsExe { $dirs = @() foreach ($rk in @('HKLM:\SOFTWARE\OBS Studio', 'HKLM:\SOFTWARE\WOW6432Node\OBS Studio')) { try { $v = (Get-Item -LiteralPath $rk -ErrorAction Stop).GetValue('') if ($v) { $dirs += [string]$v } } catch {} } if ($env:ProgramFiles) { $dirs += (Join-Path $env:ProgramFiles 'obs-studio') } if (${env:ProgramFiles(x86)}) { $dirs += (Join-Path ${env:ProgramFiles(x86)} 'obs-studio') } foreach ($d in $dirs) { $p = Join-Path $d 'bin\64bit\obs64.exe' if (Test-Path -LiteralPath $p) { return $p } } return '' } $script:ObsExe = FindObsExe # --- lista de tweaks / tweak list ------------------------------- function Tweaks ($prio) { $games = 'HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Multimedia\SystemProfile\Tasks\Games' $pname = switch ([string]$prio) { '3' { 'High (3)' } '6' { 'Above Normal (6)' } default { "($prio)" } } $list = @( @{ K = 'HKCU\System\GameConfigStore'; N = 'GameDVR_Enabled'; T = 'REG_DWORD'; D = '0'; L = 'Game DVR desligado' } @{ K = 'HKCU\System\GameConfigStore'; N = 'GameDVR_FSEBehaviorMode'; T = 'REG_DWORD'; D = '2'; L = 'FSE behavior mode = 2' } @{ K = 'HKLM\SYSTEM\CurrentControlSet\Control\Power\PowerThrottling'; N = 'PowerThrottlingOff'; T = 'REG_DWORD'; D = '1'; L = 'Power Throttling desligado' } @{ K = 'HKLM\SOFTWARE\Microsoft\Windows\Dwm'; N = 'OverlayTestMode'; T = 'REG_DWORD'; D = '5'; L = 'DWM OverlayTestMode = 5' } @{ K = $games; N = 'GPU Priority'; T = 'REG_DWORD'; D = '8'; L = 'Games: GPU Priority = 8' } @{ K = $games; N = 'Priority'; T = 'REG_DWORD'; D = '6'; L = 'Games: Priority = 6' } @{ K = $games; N = 'Scheduling Category'; T = 'REG_SZ'; D = 'High'; L = 'Games: Scheduling Category = High' } @{ K = $games; N = 'SFIO Priority'; T = 'REG_SZ'; D = 'High'; L = 'Games: SFIO Priority = High' } @{ K = "$IFEO_OBS\PerfOptions"; N = 'CpuPriorityClass'; T = 'REG_DWORD'; D = [string]$prio; L = ('OBS (obs64.exe): CPU prio = ' + $pname) } @{ K = "$IFEO_OBS\PerfOptions"; N = 'IoPriority'; T = 'REG_DWORD'; D = '3'; L = 'OBS (obs64.exe): I/O prio = High' } ) if ($script:ObsExe) { $list += @{ K = $GPUPREF_K; N = $script:ObsExe; T = 'REG_SZ'; D = 'GpuPreference=2;'; L = 'OBS: GPU de alto desempenho (Config. de Graficos)' } } return $list } # --- tela de confirmacao / confirm screen -------------------- function Confirm ($prio) { Header $w = 58 Write-Host (' ' + $YL + 'Isto sera gravado no Registro do Windows:' + $RS) Write-Host '' $rows = @( 'GameConfigStore GameDVR_Enabled 0', 'GameConfigStore GameDVR_FSEBehaviorMode 2', 'PowerThrottling PowerThrottlingOff 1', 'Dwm OverlayTestMode 5', 'Tasks\Games GPU Priority 8', 'Tasks\Games Priority 6', 'Tasks\Games Scheduling Category High', 'Tasks\Games SFIO Priority High', ('IFEO obs64.exe CpuPriorityClass ' + $prio), 'IFEO obs64.exe IoPriority 3') if ($script:ObsExe) { $rows += 'Graficos obs64.exe -> Alto desempenho' } Write-Host (' ' + $DM + '┌' + ('─' * $w) + '┐' + $RS) foreach ($r in $rows) { $s = ' ' + $r $s = $s + (' ' * [Math]::Max(0, $w - $s.Length)) Write-Host (' ' + $DM + '│' + $RS + $TX + $s + $RS + $DM + '│' + $RS) } Write-Host (' ' + $DM + '└' + ('─' * $w) + '┘' + $RS) Write-Host '' Write-Host (' ' + $DM + 'IFEO faz o Windows por o obs64.exe em prioridade' + $RS) Write-Host (' ' + $DM + 'sozinho, toda vez que o OBS abre. Nada roda em fundo.' + $RS) if ($script:ObsExe) { Write-Host (' ' + $DM + 'OBS encontrado em:' + $RS) Write-Host (' ' + (fg 170 176 196) + $script:ObsExe + $RS) } else { Write-Host (' ' + $YL + 'OBS nao encontrado no PC: o ajuste de GPU sera pulado.' + $RS) Write-Host (' ' + $DM + '(a prioridade via IFEO funciona mesmo assim)' + $RS) } Write-Host '' Write-Host (' ' + $DM + 'backup .reg em ' + $RS + (fg 170 176 196) + (Join-Path $ScriptDir 'Backup_RMS_OBS') + $RS) Write-Host '' Write-Host (' ' + (bgc 30 90 55) + $BLD + ' S ' + $RS + $TX + ' aplicar agora ' + $RS + (bgc 100 35 40) + $BLD + ' N ' + $RS + $TX + ' cancelar' + $RS) while ($true) { $k = [Console]::ReadKey($true) $c = [string]$k.KeyChar if ($c -match '^[sySY]$') { return $true } if ($c -match '^[nN]$' -or $k.Key -eq 'Escape') { return $false } } } # --- aplicar / apply --------------------------------------- function RunApply ($prio) { Header Write-Host (' ' + $WH + $BLD + "1 $DOT BACKUP" + $RS) Write-Host '' $stamp = Get-Date -Format 'yyyy-MM-dd_HH-mm-ss' $bkdir = Join-Path (Join-Path $ScriptDir 'Backup_RMS_OBS') $stamp New-Item -ItemType Directory -Force -Path $bkdir | Out-Null $bkeys = @( @{ K = 'HKCU\System\GameConfigStore'; F = 'GameConfigStore.reg' } @{ K = 'HKLM\SYSTEM\CurrentControlSet\Control\Power\PowerThrottling'; F = 'PowerThrottling.reg' } @{ K = 'HKLM\SOFTWARE\Microsoft\Windows\Dwm'; F = 'Dwm.reg' } @{ K = 'HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Multimedia\SystemProfile\Tasks\Games'; F = 'Tasks_Games.reg' } @{ K = $IFEO_OBS; F = 'IFEO_obs64_exe.reg' } @{ K = $GPUPREF_K; F = 'UserGpuPreferences.reg' } ) foreach ($x in $bkeys) { SLine $x.F Start-Sleep -Milliseconds 55 if (RegRun query $x.K) { if (RegRun export $x.K (Join-Path $bkdir $x.F) /y) { SOk ('backup ' + $x.F) } else { SWarn ('sem backup ' + $x.F) } } else { Set-Content -LiteralPath (Join-Path $bkdir ('MISSING_' + $x.F + '.txt')) -Value $x.K -Encoding ASCII SWarn ('nao existia, ok ' + $x.F) } } Write-Host '' Write-Host (' ' + $WH + $BLD + "2 $DOT APLICANDO / APPLYING" + $RS) Write-Host '' $tw = Tweaks $prio $done = 0; $fail = 0 foreach ($t in $tw) { SLine $t.L Start-Sleep -Milliseconds 70 if (RegRun add $t.K /v $t.N /t $t.T /d $t.D /f) { SOk $t.L; $done++ } else { SFail $t.L; $fail++ } } Write-Host '' Write-Host (Bar $tw.Count $done) Write-Host '' if ($fail -eq 0) { GBox @( "TWEAKS APLICADOS $DOT REINICIE O PC", "TWEAKS APPLIED $DOT RESTART YOUR PC", "OBS: prioridade automatica ao abrir") $GR } else { GBox @("$fail item(s) falharam.", 'Feche e rode como administrador.') $YL } if (-not $script:ObsExe) { Write-Host (' ' + $DM + 'OBS nao encontrado: ajuste de GPU foi pulado.' + $RS) } Write-Host '' Write-Host (' ' + $DM + 'backup: ' + $RS + (fg 170 176 196) + $bkdir + $RS) Write-Host '' Write-Host (' ' + $MG + $BLD + 'curtiu? compartilha com a galera e segue @rms.tech' + $RS) try { Start-Process 'https://otimizar.superpackultimate.com/?de=packs' } catch {} Pause2 } # --- restaurar / restore -------------------------------- function RunRestore { Header Write-Host (' ' + $WH + $BLD + 'RESTAURAR / RESTORE' + $RS) Write-Host '' $bkroot = Join-Path $ScriptDir 'Backup_RMS_OBS' if (-not (Test-Path -LiteralPath $bkroot)) { GBox @('Nenhum backup encontrado.', 'No backup found.') $RD Pause2; return } $latest = Get-ChildItem -LiteralPath $bkroot -Directory -ErrorAction SilentlyContinue | Sort-Object Name -Descending | Select-Object -First 1 if (-not $latest) { GBox @('Nenhum backup encontrado.', 'No backup found.') $RD Pause2; return } Write-Host (' ' + $DM + 'de / from: ' + $RS + (fg 170 176 196) + $latest.FullName + $RS) Write-Host '' Write-Host (' ' + $WH + $BLD + 'removendo valores adicionados / removing added values' + $RS) Write-Host '' foreach ($t in (Tweaks '0')) { SLine ('remover ' + $t.N) Start-Sleep -Milliseconds 40 [void](RegRun delete $t.K /v $t.N /f) SOk ('removido ' + $t.N) } Write-Host '' Write-Host (' ' + $WH + $BLD + 'reimportando originais / re-importing originals' + $RS) Write-Host '' $imported = 0 Get-ChildItem -LiteralPath $latest.FullName -Filter *.reg -ErrorAction SilentlyContinue | ForEach-Object { SLine ('import ' + $_.Name) Start-Sleep -Milliseconds 40 if (RegRun import $_.FullName) { SOk ('import ' + $_.Name); $imported++ } else { SFail ('import ' + $_.Name) } } if ($imported -eq 0) { Write-Host (' ' + $DM + ' (nenhum .reg neste backup)' + $RS) } foreach ($mk in (Get-ChildItem -LiteralPath $latest.FullName -Filter 'MISSING_*.txt' -ErrorAction SilentlyContinue)) { $origKey = (Get-Content -LiteralPath $mk.FullName -Raw).Trim() [void](RegRun delete $origKey /f) SWarn ('chave removida (nao existia antes) ' + $mk.Name) } Write-Host '' GBox @("RESTAURADO $DOT REINICIE O PC", "RESTORED $DOT RESTART YOUR PC") $GR Pause2 } # ============================ MAIN ===================================== try { [Console]::CursorVisible = $false } catch {} try { while ($true) { $c = Menu @( @{ Id = 'APPLY'; Key = '1'; Text = "Aplicar otimizacoes $DOT Apply tweaks" } @{ Id = 'RESTORE'; Key = '2'; Text = "Restaurar ultimo backup $DOT Restore backup" } @{ Id = 'EXIT'; Key = '3'; Text = "Sair $DOT Exit" } ) '' if ($c -eq 'APPLY') { $s = Menu @( @{ Id = '3'; Key = 'A'; Text = 'Prioridade High (3) · recomendado' } @{ Id = '6'; Key = 'B'; Text = 'Prioridade Above Normal (6) · mais suave' } ) 'Prioridade de CPU do obs64.exe (na duvida, use a A):' if ($s -eq '6' -or $s -eq '3') { if (Confirm $s) { RunApply $s } } } elseif ($c -eq 'RESTORE') { RunRestore } elseif ($c -eq 'EXIT' -or $c -eq 'BACK') { break } } } catch { Write-Host '' Write-Host (' ' + $RD + $BLD + 'ERRO INESPERADO / UNEXPECTED ERROR:' + $RS) Write-Host (' ' + $TX + $_.Exception.Message + $RS) Write-Host '' Write-Host (' ' + $DM + 'pressione qualquer tecla para fechar...' + $RS) try { [void][Console]::ReadKey($true) } catch { Read-Host | Out-Null } } finally { try { [Console]::CursorVisible = $true } catch {} Write-Host $RS Write-Host '' }