$ErrorActionPreference = "SilentlyContinue" Write-Host "DdingStory Wuthering Waves import helper" -ForegroundColor Cyan Write-Host "This script only reads local Wuthering Waves log files and copies the Convene URL." -ForegroundColor DarkGray Write-Host "" $normalUrlPattern = "https://aki-gm-resources(-oversea)?\.aki-game\.(net|com)/aki/gacha/index\.html#/record[^`"'\s]*" $escapedUrlPattern = "https:\\/\\/aki-gm-resources(-oversea)?\.aki-game\.(net|com)\\/aki\\/gacha\\/index\.html#\\/record[^`"'\s]*" $encodedUrlPattern = "https(?:%3[aA]|:)(?:%2[fF]|/)(?:%2[fF]|/)aki-gm-resources(-oversea)?(?:\.|%2[eE])aki-game(?:\.|%2[eE])(net|com)(?:%2[fF]|/)aki(?:%2[fF]|/)gacha(?:%2[fF]|/)index(?:\.|%2[eE])html(?:%23|#)(?:%2[fF]|/)record[^`"'\s]*" $checkedRoots = New-Object "System.Collections.Generic.HashSet[string]" ([System.StringComparer]::OrdinalIgnoreCase) $queuedLogs = New-Object "System.Collections.Generic.List[object]" function Normalize-ConveneUrl { param([string]$Url) if ([string]::IsNullOrWhiteSpace($Url)) { return $null } $normalized = $Url.Trim().Trim('"').Trim("'") $normalized = $normalized -replace "\\u0026", "&" $normalized = $normalized -replace "\\u003d", "=" $normalized = $normalized -replace "\\u003f", "?" $normalized = $normalized -replace "\\u0023", "#" $normalized = $normalized -replace "\\u002f", "/" $normalized = $normalized -replace "\\u003a", ":" $normalized = $normalized -replace "\\/", "/" $normalized = [System.Net.WebUtility]::HtmlDecode($normalized) for ($i = 0; $i -lt 3; $i++) { if ($normalized -notmatch "%(?:25)?(?:2[fF]|3[aA]|23|3[fF]|3[dD]|26)") { break } try { $decoded = [System.Uri]::UnescapeDataString($normalized) if ($decoded -eq $normalized) { break } $normalized = $decoded } catch { break } } return $normalized.Trim().TrimEnd([char[]]@(",", ";", ")")) } function Test-ConveneUrl { param([string]$Url) $normalized = Normalize-ConveneUrl $Url if ([string]::IsNullOrWhiteSpace($normalized)) { return $false } try { $parsed = [System.Uri]$normalized } catch { return $false } if ($parsed.Scheme -ne "https") { return $false } if ($parsed.Host -notmatch "^(?i:aki-gm-resources(-oversea)?\.aki-game\.(net|com))$") { return $false } $haystack = "$($parsed.Query)&$($parsed.Fragment)" foreach ($key in @("record_id", "player_id", "svr_id", "resources_id")) { if ($haystack -notmatch "(^|[?&#])$([regex]::Escape($key))=") { return $false } } return $true } function Add-UniqueValue { param( [System.Collections.Generic.List[string]]$List, [string]$Value ) if ([string]::IsNullOrWhiteSpace($Value)) { return } $normalized = $Value.Trim().Trim('"').TrimEnd("\") if ([string]::IsNullOrWhiteSpace($normalized)) { return } if (!$List.Contains($normalized)) { [void]$List.Add($normalized) } } function Expand-GameRootCandidate { param([string]$Path) $results = New-Object "System.Collections.Generic.List[string]" if ([string]::IsNullOrWhiteSpace($Path)) { return $results } $candidate = $Path.Trim().Trim('"').TrimEnd("\") Add-UniqueValue $results $candidate Add-UniqueValue $results (Join-Path $candidate "Wuthering Waves Game") if ($candidate -match "(?i)^(.*)\\Client(\\|$)") { Add-UniqueValue $results $Matches[1] } return $results } function Queue-LogFile { param( [string]$Path, [string]$Type ) if (!(Test-Path -LiteralPath $Path -PathType Leaf)) { return } $item = Get-Item -LiteralPath $Path [void]$queuedLogs.Add([PSCustomObject]@{ Path = $item.FullName Type = $Type LastWriteTime = $item.LastWriteTime }) } function Queue-LogsFromRoot { param([string]$Root) if ([string]::IsNullOrWhiteSpace($Root)) { return } $rootPath = $Root.TrimEnd("\") if ($checkedRoots.Contains($rootPath)) { return } [void]$checkedRoots.Add($rootPath) if (!(Test-Path -LiteralPath $rootPath -PathType Container)) { return } $logsDir = Join-Path $rootPath "Client\Saved\Logs" if (Test-Path -LiteralPath $logsDir -PathType Container) { Get-ChildItem -LiteralPath $logsDir -Filter "*.log" -File | ForEach-Object { $logType = "text" if ($_.Name -like "Client*.log") { $logType = "client" } Queue-LogFile $_.FullName $logType } } Queue-LogFile (Join-Path $rootPath "Client\Binaries\Win64\ThirdParty\KrPcSdk_Global\KRSDKRes\KRSDKWebView\debug.log") "debug" $webViewLogDir = Join-Path $rootPath "Client\Binaries\Win64\ThirdParty\KrPcSdk_Global\KRSDKRes\KRSDKWebView\log" if (Test-Path -LiteralPath $webViewLogDir -PathType Container) { Get-ChildItem -LiteralPath $webViewLogDir -Filter "*.log" -File | ForEach-Object { Queue-LogFile $_.FullName "debug" } } } function Read-SharedFileBytes { param([string]$Path) $stream = $null $memoryStream = $null try { $fileShare = [System.IO.FileShare]([System.IO.FileShare]::ReadWrite -bor [System.IO.FileShare]::Delete) $stream = [System.IO.File]::Open($Path, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, $fileShare) $memoryStream = [System.IO.MemoryStream]::new() $stream.CopyTo($memoryStream) return ,$memoryStream.ToArray() } finally { if ($memoryStream) { $memoryStream.Dispose() } if ($stream) { $stream.Dispose() } } } function Get-SharedFileContent { param([string]$Path) $bytes = Read-SharedFileBytes $Path return [System.Text.Encoding]::UTF8.GetString($bytes) } function Get-DecodedClientLogContent { param([string]$Path) $bytes = Read-SharedFileBytes $Path if ($null -eq $bytes -or $bytes.Length -eq 0) { return "" } for ($i = 0; $i -lt $bytes.Length; $i++) { $byte = [int]$bytes[$i] if ((($byte -band 0x0F) % 2) -eq 1) { $bytes[$i] = [byte]($byte -bxor 0xA5) } else { $bytes[$i] = [byte]($byte -bxor 0xEF) } } return [System.Text.Encoding]::UTF8.GetString($bytes) } function Get-ConveneUrlFromText { param([string]$Text) if ([string]::IsNullOrWhiteSpace($Text)) { return $null } foreach ($pattern in @($normalUrlPattern, $escapedUrlPattern, $encodedUrlPattern)) { $matches = [regex]::Matches($Text, $pattern, [System.Text.RegularExpressions.RegexOptions]::IgnoreCase) for ($i = $matches.Count - 1; $i -ge 0; $i--) { $candidate = Normalize-ConveneUrl $matches[$i].Value if (Test-ConveneUrl $candidate) { return $candidate } } } return $null } function Extract-ConveneUrlFromLog { param([object]$LogFile) if ($LogFile.Type -eq "client") { try { $decodedUrl = Get-ConveneUrlFromText (Get-DecodedClientLogContent $LogFile.Path) if ($decodedUrl) { return $decodedUrl } } catch { } } try { return Get-ConveneUrlFromText (Get-SharedFileContent $LogFile.Path) } catch { return $null } } function Get-RegistryInstallPaths { $registryRoots = @( "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*", "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*", "Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" ) foreach ($registryRoot in $registryRoots) { Get-ItemProperty -Path $registryRoot | Where-Object { $_.DisplayName -like "*Wuthering*" -or $_.DisplayName -like "*Wuthering Waves*" } | ForEach-Object { if ($_.InstallPath) { $_.InstallPath } if ($_.InstallLocation) { $_.InstallLocation } } } } function Get-MuiCachePaths { $muiCachePath = "Registry::HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache" Get-ItemProperty -Path $muiCachePath | Select-Object -ExpandProperty PSObject | Select-Object -ExpandProperty Properties | Where-Object { $_.Value -like "*wuthering*" -and $_.Name -like "*client-win64-shipping.exe*" } | ForEach-Object { ($_.Name -split "\\Client\\")[0] } } function Get-FirewallPaths { $firewallPath = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules" Get-ItemProperty -Path $firewallPath | Select-Object -ExpandProperty PSObject | Select-Object -ExpandProperty Properties | Where-Object { $_.Value -like "*wuthering*" -and $_.Value -like "*client-win64-shipping*" } | ForEach-Object { if ($_.Value -match "App=([^|]+)") { ($Matches[1] -split "\\Client\\")[0] } } } function Get-CommonInstallPaths { $drives = Get-PSDrive -PSProvider FileSystem | Select-Object -ExpandProperty Root foreach ($drive in $drives) { @( "${drive}SteamLibrary\steamapps\common\Wuthering Waves", "${drive}SteamLibrary\steamapps\common\Wuthering Waves\Wuthering Waves Game", "${drive}Steam\steamapps\common\Wuthering Waves", "${drive}Steam\steamapps\common\Wuthering Waves\Wuthering Waves Game", "${drive}Games\Steam\steamapps\common\Wuthering Waves", "${drive}Games\Steam\steamapps\common\Wuthering Waves\Wuthering Waves Game", "${drive}Program Files\Steam\steamapps\common\Wuthering Waves", "${drive}Program Files\Steam\steamapps\common\Wuthering Waves\Wuthering Waves Game", "${drive}Program Files (x86)\Steam\steamapps\common\Wuthering Waves", "${drive}Program Files (x86)\Steam\steamapps\common\Wuthering Waves\Wuthering Waves Game", "${drive}Program Files\Epic Games\WutheringWavesj3oFh", "${drive}Program Files\Epic Games\WutheringWavesj3oFh\Wuthering Waves Game", "${drive}Program Files (x86)\Epic Games\WutheringWavesj3oFh", "${drive}Program Files (x86)\Epic Games\WutheringWavesj3oFh\Wuthering Waves Game", "${drive}Program Files\Wuthering Waves", "${drive}Program Files\Wuthering Waves\Wuthering Waves Game", "${drive}Program Files (x86)\Wuthering Waves", "${drive}Program Files (x86)\Wuthering Waves\Wuthering Waves Game", "${drive}Games\Wuthering Waves", "${drive}Games\Wuthering Waves\Wuthering Waves Game", "${drive}Games\Wuthering Waves Game", "${drive}Wuthering Waves", "${drive}Wuthering Waves\Wuthering Waves Game", "${drive}Wuthering Waves Game" ) } } $candidateRoots = New-Object "System.Collections.Generic.List[string]" foreach ($path in (Get-RegistryInstallPaths)) { foreach ($expanded in (Expand-GameRootCandidate $path)) { Add-UniqueValue $candidateRoots $expanded } } foreach ($path in (Get-MuiCachePaths)) { foreach ($expanded in (Expand-GameRootCandidate $path)) { Add-UniqueValue $candidateRoots $expanded } } foreach ($path in (Get-FirewallPaths)) { foreach ($expanded in (Expand-GameRootCandidate $path)) { Add-UniqueValue $candidateRoots $expanded } } foreach ($path in (Get-CommonInstallPaths)) { Add-UniqueValue $candidateRoots $path } Write-Host "Searching known install locations..." -ForegroundColor Yellow foreach ($root in $candidateRoots) { Queue-LogsFromRoot $root } if ($queuedLogs.Count -eq 0) { Write-Host "" Write-Host "Automatic detection failed. No log files were found." -ForegroundColor Red Write-Host "Common paths checked include Steam, Epic Games, Program Files, Games, and root-drive installs." -ForegroundColor Yellow exit 1 } $rankedLogs = $queuedLogs | Sort-Object LastWriteTime -Descending | Group-Object Path | ForEach-Object { $_.Group[0] } Write-Host "Found $($rankedLogs.Count) log file(s). Checking newest first..." -ForegroundColor DarkGray foreach ($log in $rankedLogs) { $foundUrl = Extract-ConveneUrlFromLog $log if ($foundUrl) { try { Set-Clipboard -Value $foundUrl -ErrorAction Stop Write-Host "" Write-Host "Convene URL found in:" -ForegroundColor Green Write-Host $log.Path -ForegroundColor DarkGray Write-Host "Log modified at: $($log.LastWriteTime)" -ForegroundColor DarkGray if ($log.LastWriteTime -lt (Get-Date).AddMinutes(-30)) { Write-Host "" Write-Host "Warning: this log is older than 30 minutes, so the copied URL may already be expired." -ForegroundColor Yellow Write-Host "Open the in-game Convene History page again, wait until the list loads, then rerun this script." -ForegroundColor Yellow } Write-Host "" Write-Host "Link copied to clipboard." -ForegroundColor Green Write-Host "Paste it into DdingStory's Convene URL field and click import." -ForegroundColor Green } catch { Write-Host "" Write-Host "Clipboard copy failed. Copy this URL manually:" -ForegroundColor Yellow Write-Output $foundUrl } exit 0 } } Write-Host "" Write-Host "Automatic detection failed. Log files were found but no Convene URL was present." -ForegroundColor Red Write-Host "Open the in-game Convene History page, wait until the history list loads, then run this command again." -ForegroundColor Yellow Write-Host "" Write-Host "Newest checked log files:" -ForegroundColor DarkGray $rankedLogs | Select-Object -First 8 | ForEach-Object { Write-Host "$($_.LastWriteTime) $($_.Path)" -ForegroundColor DarkGray } exit 1