param(
    [string]$GameRoot = "D:\SteamLibrary\steamapps\common\ProjectZomboid"
)

$ErrorActionPreference = "Stop"

$targets = @(
    (Join-Path $GameRoot "zombie\vehicles\BaseVehicle.class"),
    (Join-Path $GameRoot "java\zombie\vehicles\BaseVehicle.class")
)
$helperTargets = @(
    (Join-Path $GameRoot "zombie\vehicles\LandtrainConstraintAuthHelper.class"),
    (Join-Path $GameRoot "java\zombie\vehicles\LandtrainConstraintAuthHelper.class")
)

$handled = $false
foreach ($targetClass in $targets | Select-Object -Unique) {
    $backupClass = "$targetClass.landtrain.original"
    if (Test-Path $backupClass) {
        Copy-Item $backupClass $targetClass -Force
        Write-Output "Restored BaseVehicle.class from $backupClass"
        $handled = $true
    } elseif (Test-Path $targetClass) {
        Remove-Item $targetClass -Force
        Write-Output "Removed override class at $targetClass (game will use class from projectzomboid.jar)"
        $handled = $true
    }
}

foreach ($helperClass in $helperTargets | Select-Object -Unique) {
    if (Test-Path $helperClass) {
        Remove-Item $helperClass -Force
        Write-Output "Removed helper override class at $helperClass"
        $handled = $true
    }
}

if (-not $handled) {
    Write-Output "No override or backup found in known client/dedicated paths. Nothing to restore."
}
