Guest User

Untitled

a guest
Dec 23rd, 2025
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Add-Type -AssemblyName System.Windows.Forms
  2.  
  3. # Save original directory
  4. $originalDir = Get-Location
  5.  
  6. # --- Build working directory for current user ---
  7. $workDir = Join-Path $env:USERPROFILE "AppData\LocalLow\Hyperstrange\Blood West"
  8. Set-Location $workDir
  9. Write-Host "Working directory set to: $workDir"
  10.  
  11. # --- GUI file picker ---
  12. $dialog = New-Object System.Windows.Forms.OpenFileDialog
  13. $dialog.InitialDirectory = $workDir
  14. $dialog.Filter = "Blood West Save (*.blood_west_save)|*.blood_west_save"
  15. $dialog.Title = "Select the .blood_west_save to repair"
  16.  
  17. if ($dialog.ShowDialog() -ne "OK") {
  18.     Write-Host "No file selected. Exiting."
  19.     Set-Location $originalDir
  20.     exit
  21. }
  22.  
  23. $custPath = $dialog.FileName
  24. Write-Host "Selected: $custPath"
  25.  
  26. # --- Create backup of original ---
  27. $backupPath = "$custPath.bak"
  28. Copy-Item -Path $custPath -Destination $backupPath -Force
  29. Write-Host "Backup created at: $backupPath"
  30.  
  31. # --- Prepare temp paths ---
  32. $tempDir  = Join-Path $env:TEMP ("zipwork_" + [guid]::NewGuid().ToString())
  33. $tempZip  = Join-Path $tempDir  "work.zip"
  34.  
  35. New-Item -ItemType Directory -Path $tempDir | Out-Null
  36.  
  37. # --- Copy .cust as .zip so Expand-Archive accepts it ---
  38. Copy-Item -Path $custPath -Destination $tempZip -Force
  39.  
  40. # --- Extract ZIP ---
  41. Expand-Archive -Path $tempZip -DestinationPath $tempDir -Force
  42.  
  43. # --- Modify Meta.json ---
  44. $metaFile = Join-Path $tempDir "Meta.json"
  45.  
  46. if (-Not (Test-Path $metaFile)) {
  47.     [System.Windows.Forms.MessageBox]::Show("Meta.json not found in archive.","Error",
  48.         [System.Windows.Forms.MessageBoxButtons]::OK,
  49.         [System.Windows.Forms.MessageBoxIcon]::Error)
  50.     Remove-Item $tempDir -Recurse -Force
  51.     Set-Location $originalDir
  52.     exit
  53. }
  54.  
  55. $json = Get-Content $metaFile -Raw | ConvertFrom-Json
  56. $json.IsDlc = $false
  57.  
  58. # Convert to JSON, then remove all newlines and extra spaces
  59. $compactJson = $json | ConvertTo-Json -Depth 10 -Compress
  60.  
  61. # Save as single-line JSON WITHOUT BOM
  62. $utf8NoBOM = New-Object System.Text.UTF8Encoding($false)  # $false = no BOM
  63. [System.IO.File]::WriteAllText($metaFile, $compactJson, $utf8NoBOM)
  64.  
  65. # --- Recreate ZIP from extracted contents ---
  66. # First remove old temp zip (we don't want to include it inside itself)
  67. Remove-Item $tempZip -Force
  68.  
  69. Compress-Archive -Path "$tempDir\*" -DestinationPath $tempZip
  70.  
  71. # --- Overwrite original .cust with new ZIP bytes ---
  72. Copy-Item -Path $tempZip -Destination $custPath -Force
  73.  
  74. # --- Cleanup ---
  75. Remove-Item $tempDir -Recurse -Force
  76.  
  77. # Return to original directory
  78. Set-Location $originalDir
  79.  
  80. # --- Success message box ---
  81. [System.Windows.Forms.MessageBox]::Show("Save repaired successfully!","Success",
  82.     [System.Windows.Forms.MessageBoxButtons]::OK,
  83.     [System.Windows.Forms.MessageBoxIcon]::Information)
  84.  
Tags: blood_west
Advertisement
Add Comment
Please, Sign In to add comment