$ErrorActionPreference = 'Stop' [Console]::OutputEncoding = [Text.Encoding]::UTF8 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $Host.UI.RawUI.WindowTitle = 'Lunar Optimizer' function Show-Banner { Clear-Host Write-Host '' Write-Host ' ==========================================' -ForegroundColor Cyan Write-Host ' LUNAR OPTIMIZER ' -ForegroundColor White Write-Host ' ==========================================' -ForegroundColor Cyan Write-Host '' } function Get-Hwid { $guid = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Cryptography' -Name MachineGuid).MachineGuid $sha = [Security.Cryptography.SHA256]::Create() $hash = $sha.ComputeHash([Text.Encoding]::UTF8.GetBytes("lunaropt:$guid")) ($hash | ForEach-Object { $_.ToString('x2') }) -join '' } function Start-LunarOptimizer { $api = 'https://cm.aivwy.ir' $dataDir = Join-Path $env:APPDATA 'LunarOptimizer' $keyFile = Join-Path $dataDir 'key.txt' New-Item -ItemType Directory -Force -Path $dataDir | Out-Null Show-Banner $key = $null if (Test-Path $keyFile) { $saved = (Get-Content $keyFile -Raw).Trim() $use = Read-Host " Saved key found ($($saved.Substring(0, [Math]::Min(10, $saved.Length)))...). Use it? [Y/n]" if ($use -notmatch '^[nN]') { $key = $saved } } if (-not $key) { $key = (Read-Host ' Paste your subscription key').Trim() } Write-Host ' Checking subscription...' -ForegroundColor DarkGray try { $body = @{ key = $key; hwid = (Get-Hwid) } | ConvertTo-Json $res = Invoke-RestMethod -Uri "$api/api/activate" -Method Post -Body $body -ContentType 'application/json' } catch { $msg = 'Could not reach the server.' try { $msg = ($_.ErrorDetails.Message | ConvertFrom-Json).error } catch {} Write-Host " [X] $msg" -ForegroundColor Red if (Test-Path $keyFile) { Remove-Item $keyFile -Force } return } Set-Content -Path $keyFile -Value $key Write-Host " [OK] Subscription valid (expires: $($res.expiresAt))" -ForegroundColor Green Start-Sleep -Milliseconds 800 & ([ScriptBlock]::Create($res.payload)) } Start-LunarOptimizer Write-Host '' Read-Host ' Press Enter to close' | Out-Null