From 3664b4f4f811c59354390a8d62ce147c8e0f422f Mon Sep 17 00:00:00 2001 From: DarkDumpTruck <131649948+DarkDumpTruck@users.noreply.github.com> Date: Sun, 10 Mar 2024 18:06:14 +0800 Subject: [PATCH] Support more reliable way to find game location from steam library. --- injector.ps1 | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/injector.ps1 b/injector.ps1 index f9bbca3f..d115e47a 100644 --- a/injector.ps1 +++ b/injector.ps1 @@ -72,18 +72,39 @@ function Download-And-Extract-Repo { } function Find-GameExe { - $gameName = "Balatro" - $steamPaths = @( - "${env:ProgramFiles(x86)}\Steam\steamapps\common\Balatro", - "${env:UserProfile}\SteamLibrary\steamapps\common\Balatro" - ) + $steamInstallPath = Get-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Valve\Steam" | Select-Object -ExpandProperty InstallPath - foreach ($path in $steamPaths) { - $exePath = Join-Path -Path $path -ChildPath "$gameName.exe" + # Check if the Steam installation path exists + if (-not(Test-Path $steamInstallPath)) + { + return "" + } + Write-Host "Found steam installation path: $steamInstallPath" + + # Construct the path to the vdf file that contains the game library information + $vdfPath = Join-Path $steamInstallPath 'steamapps\libraryfolders.vdf' + + # Read the vdf file and convert it to a hashtable + $vdfContent = Get-Content $vdfPath -Raw + $paths = [Regex]::Matches($vdfContent, '"path"\s+"([^"]+)"') | ForEach-Object { $_.Groups[1].Value -replace '\\\\', '\' } + + # Construct the full game path for each library folder and check if it exists + $gameFolder = 'steamapps\common\Balatro' + foreach ($path in $paths) { + $gamePath = Join-Path $path $gameFolder + $exePath = Join-Path $gamePath "Balatro.exe" if (Test-Path $exePath) { return $exePath } } + return "" +} + +function Find-Or-Prompt-GameExe { + $foundPath = Find-GameExe + if ($foundPath) { + return $foundPath + } # If not found, prompt the user $userInputPath = Read-Host "Unable to locate $gameName automatically. Please enter the full path to $gameName.exe" @@ -99,7 +120,7 @@ $7ZipPath = Find-7Zip $mergedContent = Download-And-Extract-Repo -url $repoUrl -downloadPath $downloadPath -extractPath $extractPath -mergedContent $mergedContent -directories $directories -$balatroExePath = Find-GameExe # Make sure to define Find-GameExe function as shown earlier +$balatroExePath = Find-Or-Prompt-GameExe $tempDirForExtraction = Join-Path -Path $env:TEMP -ChildPath ([System.IO.Path]::GetRandomFileName()) Write-Host "Temporary directory for extraction: $tempDirForExtraction"