Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Add-Type -AssemblyName System.Windows.Forms
- # Save original directory
- $originalDir = Get-Location
- # --- Build working directory for current user ---
- $workDir = Join-Path $env:USERPROFILE "AppData\LocalLow\Hyperstrange\Blood West"
- Set-Location $workDir
- Write-Host "Working directory set to: $workDir"
- # --- GUI file picker ---
- $dialog = New-Object System.Windows.Forms.OpenFileDialog
- $dialog.InitialDirectory = $workDir
- $dialog.Filter = "Blood West Save (*.blood_west_save)|*.blood_west_save"
- $dialog.Title = "Select the .blood_west_save to repair"
- if ($dialog.ShowDialog() -ne "OK") {
- Write-Host "No file selected. Exiting."
- Set-Location $originalDir
- exit
- }
- $custPath = $dialog.FileName
- Write-Host "Selected: $custPath"
- # --- Create backup of original ---
- $backupPath = "$custPath.bak"
- Copy-Item -Path $custPath -Destination $backupPath -Force
- Write-Host "Backup created at: $backupPath"
- # --- Prepare temp paths ---
- $tempDir = Join-Path $env:TEMP ("zipwork_" + [guid]::NewGuid().ToString())
- $tempZip = Join-Path $tempDir "work.zip"
- New-Item -ItemType Directory -Path $tempDir | Out-Null
- # --- Copy .cust as .zip so Expand-Archive accepts it ---
- Copy-Item -Path $custPath -Destination $tempZip -Force
- # --- Extract ZIP ---
- Expand-Archive -Path $tempZip -DestinationPath $tempDir -Force
- # --- Modify Meta.json ---
- $metaFile = Join-Path $tempDir "Meta.json"
- if (-Not (Test-Path $metaFile)) {
- [System.Windows.Forms.MessageBox]::Show("Meta.json not found in archive.","Error",
- [System.Windows.Forms.MessageBoxButtons]::OK,
- [System.Windows.Forms.MessageBoxIcon]::Error)
- Remove-Item $tempDir -Recurse -Force
- Set-Location $originalDir
- exit
- }
- $json = Get-Content $metaFile -Raw | ConvertFrom-Json
- $json.IsDlc = $false
- # Convert to JSON, then remove all newlines and extra spaces
- $compactJson = $json | ConvertTo-Json -Depth 10 -Compress
- # Save as single-line JSON WITHOUT BOM
- $utf8NoBOM = New-Object System.Text.UTF8Encoding($false) # $false = no BOM
- [System.IO.File]::WriteAllText($metaFile, $compactJson, $utf8NoBOM)
- # --- Recreate ZIP from extracted contents ---
- # First remove old temp zip (we don't want to include it inside itself)
- Remove-Item $tempZip -Force
- Compress-Archive -Path "$tempDir\*" -DestinationPath $tempZip
- # --- Overwrite original .cust with new ZIP bytes ---
- Copy-Item -Path $tempZip -Destination $custPath -Force
- # --- Cleanup ---
- Remove-Item $tempDir -Recurse -Force
- # Return to original directory
- Set-Location $originalDir
- # --- Success message box ---
- [System.Windows.Forms.MessageBox]::Show("Save repaired successfully!","Success",
- [System.Windows.Forms.MessageBoxButtons]::OK,
- [System.Windows.Forms.MessageBoxIcon]::Information)
Advertisement
Add Comment
Please, Sign In to add comment