Emberveil sourcelauncher/Update-Client.ps1
function Resolve-EmberveilClient {
param([Parameter(Mandatory=$true)][string]$Root, [Parameter(Mandatory=$true)][string]$BundledJar)
# Updates use immutable filenames so an open client is never overwritten.
$updateRoot = Join-Path $Root 'runtime/client-updates'
$pending = $null
try {
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
$response = Invoke-WebRequest -UseBasicParsing -Uri 'https://downloads.emberveil.net/client/latest.json' -TimeoutSec 8
$manifest = $response.Content | ConvertFrom-Json
if ($manifest.sha256 -notmatch '^[a-f0-9]{64}$' -or $manifest.bytes -lt 100000 -or $manifest.bytes -gt 33554432) { throw 'Invalid client manifest.' }
$cacheVersion = (Get-Content -LiteralPath (Join-Path $Root 'game/2006Scape Server/data/cache/emberveil-cache-version.txt') -Raw).Trim()
if ($manifest.cacheVersion -ne $cacheVersion) {
Write-Host 'A full game update is available. Download the latest ZIP from play.emberveil.net.'
return $BundledJar
}
New-Item -ItemType Directory -Path $updateRoot -Force | Out-Null
$updatedJar = Join-Path $updateRoot ($manifest.sha256 + '.jar')
if (Test-Path -LiteralPath $updatedJar) {
if ((Get-Item -LiteralPath $updatedJar).Length -eq $manifest.bytes -and (Get-FileHash -LiteralPath $updatedJar -Algorithm SHA256).Hash -eq $manifest.sha256) { return $updatedJar }
}
Write-Host 'Updating Emberveil...'
$pending = Join-Path $updateRoot ([Guid]::NewGuid().ToString('N') + '.download')
# The manifest cannot redirect the launcher to an arbitrary download host.
Invoke-WebRequest -UseBasicParsing -Uri 'https://downloads.emberveil.net/client/Emberveil-Client.jar' -TimeoutSec 45 -OutFile $pending
if ((Get-Item -LiteralPath $pending).Length -ne $manifest.bytes -or (Get-FileHash -LiteralPath $pending -Algorithm SHA256).Hash -ne $manifest.sha256) { throw 'Client download verification failed.' }
Move-Item -LiteralPath $pending -Destination $updatedJar -Force
$pending = $null
Write-Host 'Emberveil is up to date.'
return $updatedJar
} catch {
Write-Host 'Update check unavailable; opening your installed Emberveil client.'
return $BundledJar
} finally {
if ($pending -and (Test-Path -LiteralPath $pending)) { Remove-Item -LiteralPath $pending -Force }
}
}