[CmdletBinding()] param( [string]$LogPath = "$env:USERPROFILE\AppData\LocalLow\Gryphline\Endfield\sdklogs\HGWebview.log", [string]$HostName = "ef-webview.gryphline.com", [switch]$SkipValidation ) $ErrorActionPreference = "Stop" try { Add-Type -AssemblyName System.Web } catch { Write-Host "Failed to load System.Web assembly. Query parsing may not work." -ForegroundColor Red return } function Write-Banner { Write-Host "========================================" -ForegroundColor Cyan Write-Host "Endfield Record URL Helper" -ForegroundColor Green Write-Host "========================================" -ForegroundColor Cyan Write-Host "" } function Read-LogContent { param([string]$Path) if (-not (Test-Path -LiteralPath $Path)) { Write-Host "Log file not found." -ForegroundColor Red Write-Host "Path checked: $Path" -ForegroundColor Yellow Write-Host "Open record history in-game first, then run again." -ForegroundColor Yellow return $null } Write-Host "Log detected." -ForegroundColor Green Write-Host "Reading data..." -ForegroundColor Cyan Write-Host "" return Get-Content -LiteralPath $Path -Raw } function Get-LatestRecordUrl { param( [string]$Content, [string]$Domain ) $pattern = "WebPortal url:\s*(https://$([regex]::Escape($Domain))[^\s]*u8_token=[^\s]+)" $hits = [regex]::Matches($Content, $pattern) if ($hits.Count -lt 1) { return $null } return $hits[$hits.Count - 1].Groups[1].Value } function Build-ApiUrl { param([string]$RecordUrl) $uri = [Uri]$RecordUrl $query = [System.Web.HttpUtility]::ParseQueryString($uri.Query) $token = $query["u8_token"] if ([string]::IsNullOrWhiteSpace($token)) { throw "Token parameter (u8_token) is missing from the extracted URL." } $serverId = $query["server"] if ([string]::IsNullOrWhiteSpace($serverId)) { $serverId = "3" } $apiBuilder = [System.UriBuilder]::new("https", $uri.Host) $apiBuilder.Path = "/api/record/char" $apiQuery = [System.Web.HttpUtility]::ParseQueryString("") $apiQuery["lang"] = "en-us" $apiQuery["pool_type"] = "E_CharacterGachaPoolType_Beginner" $apiQuery["token"] = $token $apiQuery["server_id"] = $serverId $apiBuilder.Query = $apiQuery.ToString() return [PSCustomObject]@{ Token = $token ServerId = $serverId ApiUrl = $apiBuilder.Uri.AbsoluteUri } } function Test-ApiUrl { param([string]$Url) try { $response = Invoke-RestMethod -Uri $Url -Method Get -TimeoutSec 10 if ($null -ne $response -and $response.code -eq 0) { Write-Host "Validation: success (code 0)." -ForegroundColor Green } else { $code = if ($null -ne $response) { $response.code } else { "unknown" } Write-Host "Validation: API responded with code $code." -ForegroundColor Yellow } } catch { Write-Host "Validation skipped due to request failure. URL may still be usable." -ForegroundColor Yellow } } Write-Banner $content = Read-LogContent -Path $LogPath if ($null -eq $content) { return } $recordUrl = Get-LatestRecordUrl -Content $content -Domain $HostName if ([string]::IsNullOrWhiteSpace($recordUrl)) { Write-Host "No matching record URL found in log." -ForegroundColor Red Write-Host "" Write-Host "Quick checklist:" -ForegroundColor Yellow Write-Host "1. Launch the game." -ForegroundColor Yellow Write-Host "2. Open summon history once." -ForegroundColor Yellow Write-Host "3. Run this script again." -ForegroundColor Yellow return } Write-Host "Record URL found." -ForegroundColor Green Write-Host "" try { $result = Build-ApiUrl -RecordUrl $recordUrl } catch { Write-Host "Could not build API URL." -ForegroundColor Red Write-Host $_.Exception.Message -ForegroundColor Red return } if (-not $SkipValidation) { Write-Host "Running quick API check..." -ForegroundColor Cyan Test-ApiUrl -Url $result.ApiUrl } Write-Host "" Write-Host "========================================" -ForegroundColor Cyan Write-Host "Extraction complete" -ForegroundColor Green Write-Host "========================================" -ForegroundColor Cyan Write-Host "" Write-Host "WebPortal URL:" -ForegroundColor White Write-Host $recordUrl -ForegroundColor Gray Write-Host "" Write-Host "Tracker API URL:" -ForegroundColor White Write-Host $result.ApiUrl -ForegroundColor White Write-Host "" try { Set-Clipboard -Value $result.ApiUrl Write-Host "API URL copied to clipboard." -ForegroundColor Green } catch { Write-Host "Could not copy to clipboard. Copy the URL manually from above." -ForegroundColor Yellow }