Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support more reliable way to find game location from steam library. #32

Merged
merged 1 commit into from
Mar 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions injector.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down