ViniciosLugli

PZ-B41-ModsAutomaticInstaller

Jul 10th, 2025
589
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 6.64 KB | Source Code | 0 0
  1. param(
  2.     [string]$SteamPath = "${env:ProgramFiles(x86)}\Steam",
  3.     [string]$GamePath = "${env:ProgramFiles(x86)}\Steam\steamapps\common\ProjectZomboid"
  4. )
  5.  
  6. $ColorSuccess = "Green"
  7. $ColorError = "Red"
  8. $ColorWarning = "Yellow"
  9. $ColorInfo = "Cyan"
  10.  
  11. function Write-ColoredMessage {
  12.     param(
  13.         [string]$Message,
  14.         [string]$Color
  15.     )
  16.     Write-Host $Message -ForegroundColor $Color
  17. }
  18.  
  19. function Test-PathExists {
  20.     param(
  21.         [string]$Path,
  22.         [string]$Description
  23.     )
  24.    
  25.     if (Test-Path $Path) {
  26.         Write-ColoredMessage "✓ $Description found: $Path" $ColorSuccess
  27.         return $true
  28.     } else {
  29.         Write-ColoredMessage "✗ $Description not found: $Path" $ColorError
  30.         return $false
  31.     }
  32. }
  33.  
  34. $ModsConfig = @(
  35.     @{
  36.         ID = "2909035179"
  37.         Name = "Better Car Physics"
  38.         SourcePath = "\mods\BetterCarPhysics\41\zombie"
  39.         DestinationPath = "\zombie"
  40.         IsFile = $false
  41.     },
  42.     @{
  43.         ID = "3119788162"
  44.         Name = "Every Texture Optimized"
  45.         SourcePath = "\mods\Every Texture Optimized\media"
  46.         DestinationPath = "\media"
  47.         IsFile = $false
  48.     },
  49.     @{
  50.         ID = "3022543997"
  51.         Name = "BetterFPS (4K optimized version)"
  52.         SourcePath = "\mods\BetterFPS\media\4k\zombie"
  53.         DestinationPath = "\zombie"
  54.         IsFile = $false
  55.     },
  56.     @{
  57.         ID = "3456462930"
  58.         Name = "Commandline FPS+++"
  59.         SourcePath = "\mods\Commandline FPS+++\media\common\commandline.txt"
  60.         DestinationPath = "\media\common\commandline.txt"
  61.         IsFile = $true
  62.     }
  63. )
  64.  
  65. Write-ColoredMessage "=== Project Zomboid Mods Auto-Installer ===" $ColorInfo
  66. Write-ColoredMessage "Starting checks..." $ColorInfo
  67. Write-Host ""
  68.  
  69. $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
  70. if (-not $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
  71.     Write-ColoredMessage "⚠️  WARNING: Running without administrator privileges." $ColorWarning
  72.     Write-ColoredMessage "   Some operations may fail if insufficient permissions." $ColorWarning
  73.     Write-Host ""
  74. }
  75.  
  76. $WorkshopPath = "$SteamPath\steamapps\workshop\content\108600"
  77.  
  78. Write-ColoredMessage "Checking base paths..." $ColorInfo
  79. $steamExists = Test-PathExists $SteamPath "Steam"
  80. $workshopExists = Test-PathExists $WorkshopPath "Project Zomboid Workshop"
  81. $gameExists = Test-PathExists $GamePath "Project Zomboid"
  82.  
  83. if (-not ($steamExists -and $workshopExists -and $gameExists)) {
  84.     Write-ColoredMessage "" $ColorError
  85.     Write-ColoredMessage "ERROR: Base paths not found!" $ColorError
  86.     Write-ColoredMessage "Please verify that:" $ColorError
  87.     Write-ColoredMessage "1. Steam is installed in the default path" $ColorError
  88.     Write-ColoredMessage "2. Project Zomboid is installed" $ColorError
  89.     Write-ColoredMessage "3. Mods have been downloaded from Steam Workshop" $ColorError
  90.     Write-Host ""
  91.     Write-ColoredMessage "Paths checked:" $ColorInfo
  92.     Write-ColoredMessage "Steam: $SteamPath" $ColorInfo
  93.     Write-ColoredMessage "Workshop: $WorkshopPath" $ColorInfo
  94.     Write-ColoredMessage "Game: $GamePath" $ColorInfo
  95.     Read-Host "Press Enter to exit"
  96.     exit 1
  97. }
  98.  
  99. Write-Host ""
  100. Write-ColoredMessage "Checking mods..." $ColorInfo
  101.  
  102. $AllModsExist = $true
  103. $ModsToInstall = @()
  104.  
  105. foreach ($mod in $ModsConfig) {
  106.     $modPath = "$WorkshopPath\$($mod.ID)"
  107.     $sourcePath = "$modPath$($mod.SourcePath)"
  108.    
  109.     Write-ColoredMessage "Checking mod: $($mod.Name)" $ColorInfo
  110.    
  111.     if (Test-Path $modPath) {
  112.         if (Test-Path $sourcePath) {
  113.             Write-ColoredMessage "  ✓ Mod files found" $ColorSuccess
  114.             $ModsToInstall += $mod
  115.         } else {
  116.             Write-ColoredMessage "  ✗ Specific mod files not found: $sourcePath" $ColorError
  117.             $AllModsExist = $false
  118.         }
  119.     } else {
  120.         Write-ColoredMessage "  ✗ Mod not found: $modPath" $ColorError
  121.         Write-ColoredMessage "    Make sure the mod is subscribed on Steam Workshop" $ColorWarning
  122.         $AllModsExist = $false
  123.     }
  124. }
  125.  
  126. if (-not $AllModsExist) {
  127.     Write-Host ""
  128.     Write-ColoredMessage "ERROR: Not all mods were found!" $ColorError
  129.     Write-ColoredMessage "Subscribe to the mods on Steam Workshop and try again." $ColorError
  130.     Read-Host "Press Enter to exit"
  131.     exit 1
  132. }
  133.  
  134. if ($ModsToInstall.Count -eq 0) {
  135.     Write-ColoredMessage "No valid mods found for installation." $ColorWarning
  136.     Read-Host "Press Enter to exit"
  137.     exit 1
  138. }
  139.  
  140. Write-Host ""
  141. Write-ColoredMessage "All mods found! ($($ModsToInstall.Count) mods)" $ColorSuccess
  142. Write-Host ""
  143.  
  144. Write-ColoredMessage "Mods to be installed:" $ColorInfo
  145. foreach ($mod in $ModsToInstall) {
  146.     Write-ColoredMessage "  • $($mod.Name)" $ColorInfo
  147. }
  148.  
  149. Write-Host ""
  150. $confirmation = Read-Host "Do you want to continue with installation? (Y/N)"
  151. if ($confirmation -notmatch '^[Yy]$') {
  152.     Write-ColoredMessage "Installation cancelled by user." $ColorWarning
  153.     exit 0
  154. }
  155.  
  156. Write-Host ""
  157. Write-ColoredMessage "Starting mod installation..." $ColorInfo
  158.  
  159. $SuccessCount = 0
  160. $ErrorCount = 0
  161.  
  162. foreach ($mod in $ModsToInstall) {
  163.     Write-Host ""
  164.     Write-ColoredMessage "Installing: $($mod.Name)" $ColorInfo
  165.    
  166.     try {
  167.         $sourcePath = "$WorkshopPath\$($mod.ID)$($mod.SourcePath)"
  168.         $destinationPath = "$GamePath$($mod.DestinationPath)"
  169.        
  170.         if ($mod.IsFile) {
  171.             $destinationDir = Split-Path $destinationPath -Parent
  172.             if (-not (Test-Path $destinationDir)) {
  173.                 New-Item -ItemType Directory -Path $destinationDir -Force | Out-Null
  174.                 Write-ColoredMessage "  Created directory: $destinationDir" $ColorInfo
  175.             }
  176.         }
  177.        
  178.         if ($mod.IsFile) {
  179.             Copy-Item -Path $sourcePath -Destination $destinationPath -Force
  180.             Write-ColoredMessage "  ✓ File replaced successfully" $ColorSuccess
  181.         } else {
  182.             if (-not (Test-Path $destinationPath)) {
  183.                 New-Item -ItemType Directory -Path $destinationPath -Force | Out-Null
  184.                 Write-ColoredMessage "  Destination folder created" $ColorInfo
  185.             }
  186.            
  187.             Copy-Item -Path "$sourcePath\*" -Destination $destinationPath -Recurse -Force
  188.             Write-ColoredMessage "  ✓ Mod content merged successfully" $ColorSuccess
  189.         }
  190.        
  191.         $SuccessCount++
  192.        
  193.     } catch {
  194.         Write-ColoredMessage "  ✗ Error installing mod: $($_.Exception.Message)" $ColorError
  195.         $ErrorCount++
  196.     }
  197. }
  198.  
  199. Write-Host ""
  200. Read-Host "Press Enter to exit"
Advertisement
Add Comment
Please, Sign In to add comment