Created
July 5, 2023 14:41
-
-
Save sxpso/288c9a092daea534b4843f551f675c2e to your computer and use it in GitHub Desktop.
✨ Get wish link in GI3.8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-Type -AssemblyName System.Web | |
$logLocation = "%userprofile%\AppData\LocalLow\miHoYo\Genshin Impact\output_log.txt"; | |
$logLocationChina = "%userprofile%\AppData\LocalLow\miHoYo\$([char]0x539f)$([char]0x795e)\output_log.txt"; | |
$reg = $args[0] | |
$apiHost = "hk4e-api-os.hoyoverse.com" | |
if ($reg -eq "china") { | |
Write-Host "Using China cache location" | |
$logLocation = $logLocationChina | |
$apiHost = "hk4e-api.mihoyo.com" | |
} | |
$tmps = $env:TEMP + '\pm.ps1'; | |
if ([System.IO.File]::Exists($tmps)) { | |
ri $tmps | |
} | |
$path = [System.Environment]::ExpandEnvironmentVariables($logLocation); | |
if (-Not [System.IO.File]::Exists($path)) { | |
Write-Host "Cannot find the log file! Make sure to open the wish history first!" -ForegroundColor Red | |
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { | |
Write-Host "Do you want to try to run the script as Administrator? Press [ENTER] to continue, or any key to cancel." | |
$keyInput = [Console]::ReadKey($true).Key | |
if ($keyInput -ne "13") { | |
return | |
} | |
$myinvocation.mycommand.definition > $tmps | |
Start-Process powershell -Verb runAs -ArgumentList "-noexit", $tmps, $reg | |
break | |
} | |
return | |
} | |
$logs = Get-Content -Path $path | |
$m = $logs -match "(?m).:/.+(GenshinImpact_Data|YuanShen_Data)" | |
$m[0] -match "(.:/.+(GenshinImpact_Data|YuanShen_Data))" >$null | |
if ($matches.Length -eq 0) { | |
Write-Host "Cannot find the wish history url! Make sure to open the wish history first!" -ForegroundColor Red | |
return | |
} | |
$gamedir = $matches[1] | |
$cachefile = "$gamedir/webCaches/2.13.0.1/Cache/Cache_Data/data_2" | |
$tmpfile = "$env:TEMP/ch_data_2" | |
Copy-Item $cachefile -Destination $tmpfile | |
function testUrl($url) { | |
$ProgressPreference = 'SilentlyContinue' | |
$uri = [System.UriBuilder]::New($url) | |
$uri.Path = "event/gacha_info/api/getGachaLog" | |
$uri.Host = $apiHost | |
$uri.Fragment = "" | |
$params = [System.Web.HttpUtility]::ParseQueryString($uri.Query) | |
$params.Set("lang", "en"); | |
$params.Set("gacha_type", 301); | |
$params.Set("size", "5"); | |
$params.Add("lang", "en-us"); | |
$uri.Query = $params.ToString() | |
$apiUrl = $uri.Uri.AbsoluteUri | |
$response = Invoke-WebRequest -Uri $apiUrl -ContentType "application/json" -UseBasicParsing -TimeoutSec 10 | ConvertFrom-Json | |
$testResult = $response.retcode -eq 0 | |
return $testResult | |
} | |
$content = Get-Content -Encoding UTF8 -Raw $tmpfile | |
$splitted = $content -split "1/0/" | |
$found = $splitted -match "e20190909gacha-v2" | |
$link = $false | |
$linkFound = $false | |
for ($i = $found.Length - 1; $i -ge 0; $i -= 1) { | |
$t = $found[$i] -match "(https.+?game_biz=)" | |
$link = $matches[0] | |
Write-Host "`rChecking Link $i" -NoNewline | |
$testResult = testUrl $link | |
if ($testResult -eq $true) { | |
$linkFound = $true | |
break | |
} | |
Sleep 1 | |
} | |
Remove-Item $tmpfile | |
Write-Host "" | |
if (-Not $linkFound) { | |
Write-Host "Cannot find the wish history url! Make sure to open the wish history first!" -ForegroundColor Red | |
return | |
} | |
$wishHistoryUrl = $link | |
Write-Host $wishHistoryUrl | |
Set-Clipboard -Value $wishHistoryUrl | |
Write-Host "Link copied to clipboard, paste it back to paimon.moe" -ForegroundColor Green |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment