118 lines
3.8 KiB
Text
118 lines
3.8 KiB
Text
# Function to query the registry
|
|
function Get-RegistryValue {
|
|
param (
|
|
[string]$path,
|
|
[string]$value
|
|
)
|
|
|
|
try {
|
|
$result = Get-ItemProperty -Path $path -ErrorAction Stop
|
|
return $result.$value
|
|
} catch {
|
|
return $null
|
|
}
|
|
}
|
|
|
|
Write-Host "Searching for Steam installation..."
|
|
|
|
# Get Steam installation path from registry
|
|
$steam_dir = Get-RegistryValue "HKLM:\SOFTWARE\Valve\Steam" "InstallPath"
|
|
|
|
if (-not $steam_dir) {
|
|
$steam_dir = Get-RegistryValue "HKLM:\SOFTWARE\WOW6432Node\Valve\Steam" "InstallPath"
|
|
}
|
|
|
|
# Fallback to searching for Steam.exe on C: drive
|
|
if (-not $steam_dir) {
|
|
Write-Host "No registry key found. Searching for Steam executable on C: drive..."
|
|
$steam_exe = Get-ChildItem -Path 'C:\' -Recurse -Include "Steam.exe" -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
|
|
if ($steam_exe) {
|
|
$steam_dir = Split-Path $steam_exe.FullName -Parent
|
|
}
|
|
}
|
|
|
|
# Fallback to searching for Steam.exe on drives from D: onwards
|
|
if (-not $steam_dir) {
|
|
Write-Host "No registry key found. Searching for Steam executable on all drives..."
|
|
$drives = Get-PSDrive -PSProvider FileSystem | Where-Object { $_.Name -gt 'C' }
|
|
|
|
foreach ($drive in $drives) {
|
|
$steam_exe = Get-ChildItem -Path "$($drive.Name):\" -Recurse -Include "Steam.exe" -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
|
|
if ($steam_exe) {
|
|
$steam_dir = Split-Path $steam_exe.FullName -Parent
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
if (-not $steam_dir) {
|
|
Write-Host "Steam installation path not found"
|
|
Read-Host "Press Enter to exit"
|
|
exit
|
|
}
|
|
|
|
Write-Host "Steam installation path: $steam_dir"
|
|
|
|
# Check for Garry's Mod installation
|
|
$gmod_dir = Join-Path $steam_dir "steamapps\common\GarrysMod"
|
|
if (-not (Test-Path (Join-Path $steam_dir "steamapps\appmanifest_4000.acf"))) {
|
|
$library_folders_path = Join-Path $steam_dir "steamapps\libraryfolders.vdf"
|
|
|
|
if (Test-Path $library_folders_path) {
|
|
$lines = Get-Content $library_folders_path
|
|
foreach ($line in $lines) {
|
|
if ($line -match '^\s*"\d+"\s+"(.+)"$') {
|
|
$library_path = $matches[1]
|
|
if (Test-Path (Join-Path $library_path "steamapps\appmanifest_4000.acf")) {
|
|
$gmod_dir = Join-Path $library_path "steamapps\common\GarrysMod"
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (-not (Test-Path $gmod_dir)) {
|
|
Write-Host "GMod installation path not found"
|
|
Read-Host "Press Enter to exit"
|
|
exit
|
|
}
|
|
|
|
Write-Host "GMod installation path: $gmod_dir"
|
|
|
|
# Confirm Garry's Mod installation path
|
|
$GMODPath = Join-Path $gmod_dir "garrysmod"
|
|
$AddonsPath = Join-Path $GMODPath "addons"
|
|
$_text = "Do you want to install in this path? It will completely wipe the previous Beatrun install if you had one!`n$GMODPath (y/n)"
|
|
$GMODConfirmation = Read-Host $_text
|
|
|
|
if ($GMODConfirmation -eq "y") {
|
|
$TempPath = Join-Path $GMODPath "temp"
|
|
$ZIPPath = Join-Path $TempPath "beatrun.zip"
|
|
$FolderPath = Join-Path $TempPath "beatrun"
|
|
$FolderMainPath = Join-Path $TempPath "beatrun-main"
|
|
New-Item -ItemType Directory -Path $TempPath -Force | Out-Null
|
|
Write-Host "Downloading the archive..."
|
|
(New-Object Net.WebClient).DownloadFile("https://github.com/JonnyBro/beatrun/archive/refs/heads/main.zip", $ZIPPath)
|
|
Write-Host "Downloaded! Unpacking..."
|
|
Expand-Archive $ZIPPath $TempPath -Force
|
|
Write-Host "Unpacked successfully!"
|
|
Rename-Item $FolderMainPath $FolderPath
|
|
Remove-Item $ZIPPath
|
|
$confirmation = Read-Host "Do you want to install modules? (Discord + Steam Presence) (y/n)"
|
|
if ($confirmation -eq "y") {
|
|
$ModulesPath = Join-Path $FolderPath "lua\*"
|
|
$NewModulesPath = Join-Path $GMODPath "lua"
|
|
Copy-Item -Path $ModulesPath -Destination $NewModulesPath -Force -Recurse
|
|
}
|
|
$AddonPath = Join-Path $FolderPath "beatrun"
|
|
$NewAddonPath = Join-Path $AddonsPath "beatrun"
|
|
if (Test-Path $NewAddonPath) {
|
|
Remove-Item $NewAddonPath -Force -Recurse
|
|
}
|
|
Move-Item -Path $AddonPath -Destination $NewAddonPath
|
|
Remove-Item $TempPath -Force -Recurse
|
|
Write-Host "Beatrun Installed!"
|
|
}
|