Emberveil source

launcher/Play.ps1

param([string]$Server = '127.0.0.1')
$ErrorActionPreference = 'Stop'
$jdk = Get-ChildItem -LiteralPath (Join-Path $PSScriptRoot '.tools') -Directory | Where-Object { Test-Path (Join-Path $_.FullName 'bin/java.exe') } | Select-Object -First 1
if (!$jdk) { throw 'Portable Java is missing. Extract the complete ZIP before launching.' }
$jar = Join-Path $PSScriptRoot 'game/2006Scape Client/target/client-1.0-jar-with-dependencies.jar'
if (!(Test-Path $jar)) { throw 'Run Build.ps1 first.' }
. (Join-Path $PSScriptRoot 'Update-Client.ps1')
$jar = Resolve-EmberveilClient -Root $PSScriptRoot -BundledJar $jar
$cache = Join-Path $PSScriptRoot 'runtime/client-cache'
$sourceCache = Join-Path $PSScriptRoot 'game/2006Scape Server/data/cache'
$sourceVersion = Join-Path $sourceCache 'emberveil-cache-version.txt'
$clientVersion = Join-Path $cache 'emberveil-cache-version.txt'
$needsRefresh = !(Test-Path (Join-Path $cache 'main_file_cache.dat'))
if (Test-Path $sourceVersion) {
    $needsRefresh = $needsRefresh -or !(Test-Path $clientVersion)
    if (!$needsRefresh) { $needsRefresh = (Get-Content $sourceVersion -Raw) -ne (Get-Content $clientVersion -Raw) }
}
if ($needsRefresh) {
    New-Item -ItemType Directory -Force $cache | Out-Null
    $handles = @()
    try {
        foreach ($file in (Get-ChildItem -LiteralPath $cache -Filter 'main_file_cache.*' -File)) {
            $handles += [IO.File]::Open($file.FullName, [IO.FileMode]::Open, [IO.FileAccess]::ReadWrite, [IO.FileShare]::None)
        }
    } catch { throw 'Close the other Emberveil client before updating its game files.' }
    finally { foreach ($handle in $handles) { $handle.Dispose() } }
    Get-ChildItem -LiteralPath $sourceCache -File | Where-Object { $_.Name.StartsWith('main_file_cache.') } | Copy-Item -Destination $cache -Force
    if (Test-Path $sourceVersion) { Copy-Item -LiteralPath $sourceVersion -Destination $clientVersion -Force }
}
Set-Location $PSScriptRoot
& (Join-Path $jdk.FullName 'bin/java.exe') '-Xmx512m' "-Demberveil.cache=$cache" -jar $jar -s $Server -no-crc -qol -no-nav -no-snow -hide-roofs