# ============================================================================ # RMS TECH - CPU 0 BOOST / Jogo fora do processador 0 # Interface + logica · by @rms.tech · distribuicao gratuita / free to share # Executado pelo RMS-TECH-CPU0-BOOST.bat (nao rode este .ps1 direto). # ============================================================================ param([switch]$Watch) $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 {} # --- dados do monitor / monitor data ----------------------------------- $DataDir = Join-Path $env:LOCALAPPDATA 'RMS-TECH-CPU0' $ListFile = Join-Path $DataDir 'jogos.txt' $LogFile = Join-Path $DataDir 'monitor.log' $TaskName = 'RMS-TECH-CPU0' $TaskCopy = Join-Path $DataDir 'RMS-TECH-CPU0-BOOST.ps1' $LinkUrl = 'https://otimizar.superpackultimate.com/?de=packs' $DefaultGames = @( 'COD.exe', 'PioneerGame.exe', 'WardogsClient-Win64-Shipping.exe', 'FC27.exe', 'TslGame-Win64-Shipping.exe', 'Bodycam-Win64-Shipping.exe') $script:Handled = @{} $script:Denied = @{} $script:LinkOpened = $false # =========================================================================== # NUCLEO: lista de jogos + afinidade (usado pela janela e pelo modo oculto) # =========================================================================== function WriteGames ($names) { if (-not (Test-Path -LiteralPath $DataDir)) { New-Item -ItemType Directory -Force -Path $DataDir | Out-Null } $lines = @( '# RMS TECH - CPU 0 BOOST - jogos que ficam fora do processador 0', '# Um executavel por linha (com ou sem .exe). Linhas com # sao ignoradas.', '') foreach ($n in $names) { $lines += ($n + '.exe') } Set-Content -LiteralPath $ListFile -Value $lines -Encoding ASCII } function EnsureList { if (-not (Test-Path -LiteralPath $ListFile)) { WriteGames ($DefaultGames | ForEach-Object { $_ -replace '(?i)\.exe$', '' }) } } # devolve os nomes SEM .exe function ReadGames { EnsureList $out = @() foreach ($l in (Get-Content -LiteralPath $ListFile -ErrorAction SilentlyContinue)) { $t = ([string]$l).Trim() if ($t -eq '' -or $t.StartsWith('#')) { continue } $t = $t -replace '(?i)\.exe$', '' if ($t -ne '') { $out += $t } } return $out } function CpuInfo { $n = [Environment]::ProcessorCount if ($n -ge 64) { $full = [int64]-1 } else { $full = ([int64]1 -shl $n) - 1 } return @{ N = $n; Full = $full } } function LogLine ($s) { try { if (-not (Test-Path -LiteralPath $DataDir)) { New-Item -ItemType Directory -Force -Path $DataDir | Out-Null } if ((Test-Path -LiteralPath $LogFile) -and ((Get-Item -LiteralPath $LogFile).Length -gt 200KB)) { Clear-Content -LiteralPath $LogFile } Add-Content -LiteralPath $LogFile -Value ((Get-Date -Format 'yyyy-MM-dd HH:mm:ss') + ' ' + $s) -Encoding ASCII } catch {} } # uma passada: tira o CPU 0 dos jogos da lista que estiverem abertos function WatchTick ($emit) { $info = CpuInfo if ($info.N -lt 2) { return } $names = ReadGames if ($names.Count -eq 0) { return } $set = @{} foreach ($n in $names) { $set[$n.ToLowerInvariant()] = $true } $alive = @{} foreach ($p in (Get-Process -ErrorAction SilentlyContinue)) { $pn = $p.ProcessName if (-not $set.ContainsKey($pn.ToLowerInvariant())) { continue } $id = $p.Id $alive[$id] = $true $cur = 0L try { $cur = [int64]$p.ProcessorAffinity } catch { if (-not $script:Denied.ContainsKey($id)) { $script:Denied[$id] = $true; & $emit ($pn + '.exe (PID ' + $id + '): sem permissao para ler a afinidade') } continue } if (($cur -band 1) -eq 0) { continue } $new = $cur -band (-bnot [int64]1) if ($new -eq 0) { continue } try { $p.ProcessorAffinity = [IntPtr]$new if (-not $script:Handled.ContainsKey($id)) { $script:Handled[$id] = $cur } & $emit ($pn + '.exe (PID ' + $id + '): fora do CPU 0 (0x{0:X} -> 0x{1:X})' -f $cur, $new) } catch { if (-not $script:Denied.ContainsKey($id)) { $script:Denied[$id] = $true; & $emit ($pn + '.exe (PID ' + $id + '): o Windows/anti-cheat nao deixou mudar a afinidade') } } } foreach ($k in @($script:Handled.Keys)) { if (-not $alive.ContainsKey($k)) { $script:Handled.Remove($k) } } foreach ($k in @($script:Denied.Keys)) { if (-not $alive.ContainsKey($k)) { $script:Denied.Remove($k) } } } # --- modo oculto: usado pela tarefa agendada / hidden mode (scheduled task) --- if ($Watch) { $created = $false $mtx = New-Object System.Threading.Mutex($true, 'Local\RMS-TECH-CPU0-WATCH', [ref]$created) if (-not $created) { exit } LogLine 'monitor automatico iniciado' while ($true) { try { WatchTick { param($s) LogLine $s } } catch { LogLine ('erro: ' + $_.Exception.Message) } Start-Sleep -Seconds 2 } exit } # =========================================================================== # INTERFACE # =========================================================================== 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 + 'CPU 0 BOOST' + $RS + $DM + " Jogo fora do processador 0 $DOT Game off CPU 0" + $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 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) } function OpenLinkOnce { if ($script:LinkOpened) { return } $script:LinkOpened = $true try { Start-Process $LinkUrl } catch {} } function CpuList ($mask) { $idx = @() for ($i = 0; $i -lt 64; $i++) { if ((($mask -shr $i) -band 1) -eq 1) { $idx += $i } } if ($idx.Count -eq 0) { return '-' } return ('CPU ' + (($idx | Select-Object -First 3) -join ',') + $(if ($idx.Count -gt 3) { ' ... CPU ' + $idx[-1] } else { '' })) } # =========================================================================== # [1] MONITOR NA JANELA # =========================================================================== function RunMonitor { Header $info = CpuInfo if ($info.N -lt 2) { GBox @('Este PC tem so 1 processador logico.', 'Nada para fazer aqui.') $YL Pause2; return } $names = ReadGames Write-Host (' ' + $WH + $BLD + 'MONITOR LIGADO / MONITOR ON' + $RS) Write-Host '' Write-Host (' ' + $TX + 'Deixe esta janela ABERTA enquanto joga.' + $RS) Write-Host (' ' + $DM + 'Quando um jogo da lista abrir, ele sai do CPU 0 em ~2 segundos.' + $RS) Write-Host (' ' + $DM + 'Ao fechar o jogo (ou parar o monitor) tudo volta ao normal.' + $RS) Write-Host '' Write-Host (' ' + $DM + 'Jogos vigiados (' + $names.Count + '):' + $RS) foreach ($n in $names) { Write-Host (' ' + $TX + ' ' + $DOT + ' ' + $n + '.exe' + $RS) } Write-Host '' Write-Host (' ' + $YL + 'Q ou Esc para parar o monitor' + $RS) Write-Host '' OpenLinkOnce $script:Handled = @{}; $script:Denied = @{} $emit = { param($s) Write-Host (' ' + $DM + (Get-Date -Format 'HH:mm:ss') + $RS + ' ' + $TX + $s + $RS) } $stop = $false while (-not $stop) { try { WatchTick $emit } catch { Write-Host (' ' + $RD + 'erro: ' + $_.Exception.Message + $RS) } for ($i = 0; $i -lt 20; $i++) { if ([Console]::KeyAvailable) { $k = [Console]::ReadKey($true) if ($k.Key -eq 'Q' -or $k.Key -eq 'Escape') { $stop = $true; break } } Start-Sleep -Milliseconds 100 } } Write-Host '' foreach ($id in @($script:Handled.Keys)) { try { $p = Get-Process -Id $id -ErrorAction Stop $p.ProcessorAffinity = [IntPtr][int64]$script:Handled[$id] Write-Host (' ' + $GR + 'afinidade restaurada ' + $RS + $TX + $p.ProcessName + '.exe (PID ' + $id + ')' + $RS) } catch {} } $script:Handled = @{} GBox @('MONITOR PARADO', 'MONITOR STOPPED') $GR Pause2 } # =========================================================================== # [2] / [3] MONITOR AUTOMATICO (tarefa agendada, sem admin) # =========================================================================== function RunAutoOn { Header Write-Host (' ' + $WH + $BLD + 'LIGAR MONITOR AUTOMATICO / AUTO-START ON' + $RS) Write-Host '' Write-Host (' ' + $DM + 'Cria uma tarefa que inicia o monitor, escondido, toda vez que' + $RS) Write-Host (' ' + $DM + 'voce entra no Windows. Nao precisa deixar janela aberta.' + $RS) Write-Host (' ' + $DM + 'Roda sem privilegio de administrador. Voce desliga em [3].' + $RS) Write-Host '' Write-Host (' ' + (bgc 30 90 55) + $BLD + ' S ' + $RS + $TX + ' ligar 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]$') { break } if ($c -match '^[nN]$' -or $k.Key -eq 'Escape') { return } } Write-Host '' try { SLine 'copiando o monitor' if (-not (Test-Path -LiteralPath $DataDir)) { New-Item -ItemType Directory -Force -Path $DataDir | Out-Null } EnsureList Copy-Item -LiteralPath $PSCommandPath -Destination $TaskCopy -Force SOk ('monitor copiado para ' + $DataDir) SLine 'criando a tarefa agendada' $user = $env:USERDOMAIN + '\' + $env:USERNAME $act = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument ('-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File "' + $TaskCopy + '" -Watch') $trg = New-ScheduledTaskTrigger -AtLogOn -User $user $pri = New-ScheduledTaskPrincipal -UserId $user -LogonType Interactive -RunLevel Limited $set = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit ([TimeSpan]::Zero) -StartWhenAvailable [void](Register-ScheduledTask -TaskName $TaskName -Action $act -Trigger $trg -Principal $pri -Settings $set -Force) SOk ('tarefa criada ' + $TaskName) SLine 'iniciando o monitor' Start-ScheduledTask -TaskName $TaskName SOk 'monitor rodando em segundo plano' Write-Host '' GBox @("MONITOR AUTOMATICO LIGADO", "AUTO-START ON") $GR Write-Host (' ' + $DM + 'log: ' + $RS + (fg 170 176 196) + $LogFile + $RS) OpenLinkOnce } catch { SFail ('nao consegui ligar: ' + $_.Exception.Message) } Pause2 } function RunAutoOff { Header Write-Host (' ' + $WH + $BLD + 'DESLIGAR MONITOR AUTOMATICO / AUTO-START OFF' + $RS) Write-Host '' $had = $null try { $had = Get-ScheduledTask -TaskName $TaskName -ErrorAction Stop } catch {} if (-not $had) { GBox @('O monitor automatico ja esta desligado.', 'Auto-start is already off.') $YL Pause2; return } try { SLine 'removendo a tarefa agendada' try { Stop-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue } catch {} Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false SOk 'tarefa removida' SLine 'parando o monitor escondido' $stopped = 0 foreach ($proc in @(Get-CimInstance Win32_Process -Filter "Name='powershell.exe'" -ErrorAction SilentlyContinue)) { if ($proc.CommandLine -and $proc.CommandLine -like '*RMS-TECH-CPU0-BOOST.ps1*-Watch*') { try { Stop-Process -Id $proc.ProcessId -Force -ErrorAction Stop; $stopped++ } catch {} } } SOk ('monitor parado (' + $stopped + ')') SLine 'devolvendo o CPU 0 aos jogos abertos' $info = CpuInfo $back = 0 foreach ($n in (ReadGames)) { foreach ($p in @(Get-Process -Name $n -ErrorAction SilentlyContinue)) { try { $cur = [int64]$p.ProcessorAffinity $no0 = $info.Full -band (-bnot [int64]1) if ($cur -eq $no0) { $p.ProcessorAffinity = [IntPtr]$info.Full; $back++ } } catch {} } } SOk ('jogos restaurados (' + $back + ')') Remove-Item -LiteralPath $TaskCopy -Force -ErrorAction SilentlyContinue Write-Host '' GBox @("MONITOR AUTOMATICO DESLIGADO", "AUTO-START OFF") $GR Write-Host (' ' + $DM + 'sua lista de jogos foi mantida em ' + $RS + (fg 170 176 196) + $DataDir + $RS) } catch { SFail ('nao consegui desligar: ' + $_.Exception.Message) } Pause2 } # =========================================================================== # [4] LISTA DE JOGOS # =========================================================================== function RunList { while ($true) { Header $names = @(ReadGames) Write-Host (' ' + $WH + $BLD + 'LISTA DE JOGOS / GAME LIST' + $RS) Write-Host '' if ($names.Count -eq 0) { Write-Host (' ' + $DM + ' (lista vazia)' + $RS) } for ($i = 0; $i -lt $names.Count; $i++) { Write-Host (' ' + $TX + (' {0,2} {1}.exe' -f ($i + 1), $names[$i]) + $RS) } Write-Host '' Write-Host (' ' + $DM + 'o nome do executavel aparece no Gerenciador de Tarefas > Detalhes' + $RS) Write-Host '' Write-Host (' ' + $YL + 'A' + $RS + $TX + ' adicionar ' + $RS + $YL + 'R' + $RS + $TX + ' remover ' + $RS + $YL + 'Esc' + $RS + $TX + ' voltar' + $RS) $k = [Console]::ReadKey($true) if ($k.Key -eq 'Escape') { return } $c = [string]$k.KeyChar if ($c -match '^[aA]$') { try { [Console]::CursorVisible = $true } catch {} Write-Host '' $t = (Read-Host ' nome do .exe (ex: MeuJogo-Win64-Shipping.exe)').Trim() try { [Console]::CursorVisible = $false } catch {} $t = $t -replace '(?i)\.exe$', '' if ($t -match '^[A-Za-z0-9_\.\- ]{1,100}$') { $exists = $false foreach ($n in $names) { if ($n -ieq $t) { $exists = $true } } if (-not $exists) { WriteGames ($names + $t) } } } elseif ($c -match '^[rR]$') { try { [Console]::CursorVisible = $true } catch {} Write-Host '' $t = (Read-Host ' numero a remover').Trim() try { [Console]::CursorVisible = $false } catch {} $num = 0 if ([int]::TryParse($t, [ref]$num) -and $num -ge 1 -and $num -le $names.Count) { $keep = @() for ($i = 0; $i -lt $names.Count; $i++) { if (($i + 1) -ne $num) { $keep += $names[$i] } } WriteGames $keep } } } } # =========================================================================== # [5] STATUS # =========================================================================== function RunStatus { Header $info = CpuInfo Write-Host (' ' + $WH + $BLD + 'STATUS' + $RS) Write-Host '' Write-Host (' ' + $TX + ('Processadores logicos: {0}' -f $info.N) + $RS) $task = $null try { $task = Get-ScheduledTask -TaskName $TaskName -ErrorAction Stop } catch {} if ($task) { Write-Host (' ' + $GR + ('Monitor automatico: LIGADO (' + $task.State + ')') + $RS) } else { Write-Host (' ' + $DM + 'Monitor automatico: desligado' + $RS) } Write-Host '' Write-Host (' ' + $WH + $BLD + 'JOGOS DA LISTA' + $RS) foreach ($n in (ReadGames)) { $procs = @(Get-Process -Name $n -ErrorAction SilentlyContinue) if ($procs.Count -eq 0) { Write-Host (' ' + $DM + (' {0}.exe - fechado' -f $n) + $RS); continue } foreach ($p in $procs) { try { $cur = [int64]$p.ProcessorAffinity if (($cur -band 1) -eq 0) { Write-Host (' ' + $GR + (' {0}.exe (PID {1}) - FORA do CPU 0 [{2}]' -f $n, $p.Id, (CpuList $cur)) + $RS) } else { Write-Host (' ' + $YL + (' {0}.exe (PID {1}) - usando o CPU 0 [{2}]' -f $n, $p.Id, (CpuList $cur)) + $RS) } } catch { Write-Host (' ' + $RD + (' {0}.exe (PID {1}) - sem permissao para ler' -f $n, $p.Id) + $RS) } } } Write-Host '' Write-Host (' ' + $DM + 'log do monitor automatico: ' + $RS + (fg 170 176 196) + $LogFile + $RS) if (Test-Path -LiteralPath $LogFile) { Write-Host '' foreach ($l in (Get-Content -LiteralPath $LogFile -Tail 6 -ErrorAction SilentlyContinue)) { Write-Host (' ' + $DM + $l + $RS) } } Pause2 } # ============================ MAIN ===================================== try { [Console]::CursorVisible = $false } catch {} try { EnsureList while ($true) { $c = Menu @( @{ Id = 'RUN'; Key = '1'; Text = "Iniciar monitor agora $DOT Start monitor" } @{ Id = 'AUTON'; Key = '2'; Text = "Ligar monitor automatico $DOT Auto-start ON" } @{ Id = 'AUTOFF'; Key = '3'; Text = "Desligar monitor automatico $DOT Auto-start OFF" } @{ Id = 'LIST'; Key = '4'; Text = "Lista de jogos $DOT Game list" } @{ Id = 'STATUS'; Key = '5'; Text = "Ver status $DOT Status" } @{ Id = 'EXIT'; Key = '6'; Text = "Sair $DOT Exit" } ) '' if ($c -eq 'RUN') { RunMonitor } elseif ($c -eq 'AUTON') { RunAutoOn } elseif ($c -eq 'AUTOFF') { RunAutoOff } elseif ($c -eq 'LIST') { RunList } elseif ($c -eq 'STATUS') { RunStatus } 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 '' }