Skip to content

Instantly share code, notes, and snippets.

@sjadema
Last active February 3, 2018 22:20
Show Gist options
  • Save sjadema/7d03a9557a66b25278c3bbc63cb05d01 to your computer and use it in GitHub Desktop.
Save sjadema/7d03a9557a66b25278c3bbc63cb05d01 to your computer and use it in GitHub Desktop.
Powershell script to remove desert map when opening PUBG (and move it back again after closing it). Place both files in the same directory and create a shortcut to the .bat (if needed).
@echo off
start powershell -WindowStyle "hidden" -Command "& '.\PUBG.ps1'"
# Determine Steam base directory and PUBG Steam ID
$steamRegistryPath = "HKCU:\Software\Valve\Steam";
$steamAppsDir = (Get-Item $steamRegistryPath).GetValue("SteamPath") + "/steamapps/common/"
$pubgSteamAppPath = Get-ChildItem "$($steamRegistryPath)/Apps" -Recurse | Where {$_.GetValue("Name") -eq "PLAYERUNKNOWN'S BATTLEGROUNDS"} | Select-Object -first 1
$pubgSteamAppId = Split-Path $pubgSteamAppPath -Leaf
$pubgMapsDirectory = "$($steamAppsDir)/PUBG/TslGame/Content/Paks"
# Create temporary folder to move the map files to
$tempDirectory = [System.IO.Path]::GetTempFileName()
Remove-Item -Path $tempDirectory
New-Item -ItemType "directory" -Path $tempDirectory | Out-Null
# Move all maps
Get-ChildItem -Path $pubgMapsDirectory | Where{$_.Name -Match "desert"} | Move-Item -Destination "$($tempDirectory)"
# Launch game
Start-Process "steam://rungameid/$($pubgSteamAppId)"
# Create watcher to see if the game stopped running
$process = $false
While ($true) {
While (!($process)) {
Start-Sleep -s 5
$process = Get-Process "TslGame" -ErrorAction SilentlyContinue
}
If ($process) {
$process.WaitForExit()
Start-Sleep -s 2
# Move maps back to original location
Get-ChildItem -Path $tempDirectory | Where{$_.Name -Match "desert"} | Move-Item -Destination "$($pubgMapsDirectory)"
Remove-Item $tempDirectory
Exit
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment