Guest User

Fix-BattlEye-Generic.ps1

a guest
Aug 9th, 2025
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2.     Fix-BattlEye-Generic.ps1
  3.     ----------------------------------------------------------
  4.     Purpose:
  5.       Generic BattlEye reset to fix BSODs caused by BEDaisy.sys across ANY BattlEye game.
  6.       - Stops/removes BEService
  7.       - Deletes BEDaisy.sys
  8.       - Cleans BattlEye folders for selected games (Steam/Epic)
  9.       - Optional "Quick Reset": driver + AppData only (no game folder touch)
  10.       - NO Steam/Epic verify here (do it manually per game)
  11.  
  12.     Works on: Windows 10/11 (x64)
  13.     Requirements: Run as Administrator
  14.  
  15.     Notes:
  16.       - Safe by default: you PICK which games to clean (or "All").
  17.       - Keeps other non-selected games’ BattlEye intact.
  18.       - After running, open your game launcher and verify files to reinstall BE.
  19. #>
  20.  
  21. # ===== Config / Logging =====
  22. $LogFile = "$PSScriptRoot\BattlEye_Fix_$(Get-Date -Format 'yyyyMMdd_HHmmss').log"
  23.  
  24. function Write-Log {
  25.     param([string]$Message, [string]$Color = "White")
  26.     $ts = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss")
  27.     $line = "[$ts] $Message"
  28.     Add-Content -Path $LogFile -Value $line
  29.     Write-Host $Message -ForegroundColor $Color
  30. }
  31.  
  32. # ===== Elevation check =====
  33. $principal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
  34. if (-not $principal.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) {
  35.     Write-Host "[!] Please run this script as Administrator. Relaunching..." -ForegroundColor Yellow
  36.     Start-Process -FilePath "powershell.exe" -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
  37.     exit
  38. }
  39.  
  40. Clear-Host
  41. Write-Host "=== Generic BattlEye (BEDaisy.sys) Reset ===" -ForegroundColor Cyan
  42. Write-Host "Log: $LogFile`n" -ForegroundColor DarkGray
  43.  
  44. # ===== Helpers =====
  45. function Stop-LaunchersAndGames {
  46.     $names = @(
  47.         "GTA5","GTAVLauncher","FiveM","Steam","SteamService",
  48.         "RockstarGamesLauncher","EpicGamesLauncher","SocialClubHelper",
  49.         "FortniteClient-Win64-Shipping","FortniteLauncher",
  50.         "DayZ","ShooterGame","Tarkov","R5Apex","RainbowSix","arma3_x64"
  51.     )
  52.     foreach ($n in $names) {
  53.         Get-Process -Name $n -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
  54.     }
  55. }
  56.  
  57. function Remove-Target {
  58.     param([string]$Path)
  59.     if (-not (Test-Path $Path)) { return }
  60.     try {
  61.         # Remove read-only and take ownership if needed
  62.         try { attrib -R $Path -ErrorAction SilentlyContinue | Out-Null } catch {}
  63.         try { takeown.exe /f "$Path" /a /r /d y | Out-Null } catch {}
  64.         try { icacls.exe "$Path" /grant "*S-1-5-32-544:(F)" /T /C | Out-Null } catch {}
  65.         Remove-Item -LiteralPath $Path -Recurse -Force -ErrorAction Stop
  66.         Write-Log "Removed: $Path" "Green"
  67.     } catch {
  68.         Write-Log "Failed to remove: $Path  ($_)" "Yellow"
  69.     }
  70. }
  71.  
  72. function Get-SteamLibraries {
  73.     $libs = @()
  74.     $reg = "HKLM:\SOFTWARE\WOW6432Node\Valve\Steam"
  75.     if (Test-Path $reg) {
  76.         $steamPath = (Get-ItemProperty -Path $reg -Name InstallPath -ErrorAction SilentlyContinue).InstallPath
  77.         if ($steamPath) { $libs += $steamPath }
  78.         $vdf = Join-Path $steamPath "steamapps\libraryfolders.vdf"
  79.         if (Test-Path $vdf) {
  80.             (Get-Content $vdf) -match '"path"\s+"([^"]+)"' | ForEach-Object {
  81.                 $m = [regex]::Match($_, '"path"\s+"([^"]+)"')
  82.                 if ($m.Success) { $libs += $m.Groups[1].Value }
  83.             }
  84.         }
  85.     }
  86.     $libs | Select-Object -Unique
  87. }
  88.  
  89. function Get-EpicRoots {
  90.     # Common Epic install roots (best-effort)
  91.     @(
  92.         "$env:ProgramFiles\Epic Games",
  93.         "$env:ProgramFiles(x86)\Epic Games",
  94.         "C:\Epic Games",
  95.         "D:\Epic Games",
  96.         "E:\Epic Games"
  97.     ) | Where-Object { Test-Path $_ } | Select-Object -Unique
  98. }
  99.  
  100. function Find-BattlEyeFolders {
  101.     # Returns objects with GameName and BEPath
  102.     $results = @()
  103.  
  104.     # Steam
  105.     foreach ($lib in Get-SteamLibraries) {
  106.         $common = Join-Path $lib "steamapps\common"
  107.         if (Test-Path $common) {
  108.             try {
  109.                 $beDirs = Get-ChildItem -LiteralPath $common -Directory -Recurse -ErrorAction SilentlyContinue |
  110.                           Where-Object { $_.Name -ieq "BattlEye" }
  111.                 foreach ($dir in $beDirs) {
  112.                     $game = Split-Path $dir.Parent.FullName -Leaf
  113.                     $results += [pscustomobject]@{
  114.                         Platform = "Steam"
  115.                         GameName = $game
  116.                         BEPath   = $dir.FullName
  117.                     }
  118.                 }
  119.             } catch {}
  120.         }
  121.     }
  122.  
  123.     # Epic (shallow scan: BattlEye folder directly under each game)
  124.     foreach ($root in Get-EpicRoots) {
  125.         try {
  126.             $games = Get-ChildItem -LiteralPath $root -Directory -ErrorAction SilentlyContinue
  127.             foreach ($g in $games) {
  128.                 $be = Join-Path $g.FullName "BattlEye"
  129.                 if (Test-Path $be) {
  130.                     $results += [pscustomobject]@{
  131.                         Platform = "Epic"
  132.                         GameName = $g.Name
  133.                         BEPath   = $be
  134.                     }
  135.                 }
  136.             }
  137.         } catch {}
  138.     }
  139.  
  140.     # De-dup by path
  141.     $results | Sort-Object BEPath -Unique
  142. }
  143.  
  144. function Clean-AppDataBattlEye-AllUsers {
  145.     Write-Log "Cleaning AppData BattlEye (all users)..." "Yellow"
  146.     Get-ChildItem "C:\Users" -Directory -ErrorAction SilentlyContinue | ForEach-Object {
  147.         $paths = @(
  148.             "$($_.FullName)\AppData\Local\BattlEye",
  149.             "$($_.FullName)\AppData\Roaming\BattlEye"
  150.         )
  151.         foreach ($p in $paths) { if (Test-Path $p) { Remove-Target $p } }
  152.     }
  153. }
  154.  
  155. function Driver-Reset {
  156.     Write-Log "Stopping & deleting BEService..." "Yellow"
  157.     sc.exe stop BEService | Out-Null
  158.     Start-Sleep -Milliseconds 500
  159.     sc.exe delete BEService | Out-Null
  160.     Start-Sleep -Milliseconds 300
  161.  
  162.     $driverCandidates = @(
  163.         "$env:WINDIR\System32\drivers\BEDaisy.sys",
  164.         "$env:WINDIR\SysWOW64\BEDaisy.sys"
  165.     )
  166.     foreach ($d in $driverCandidates) {
  167.         if (Test-Path $d) { Remove-Target $d }
  168.     }
  169.  
  170.     Clean-AppDataBattlEye-AllUsers
  171. }
  172.  
  173. # ===== Main Flow =====
  174. Write-Log "Stopping running launchers/games..." "Gray"
  175. Stop-LaunchersAndGames
  176. Start-Sleep -Seconds 1
  177.  
  178. Write-Log "Scanning for BattlEye folders in Steam/Epic..." "Gray"
  179. $found = Find-BattlEyeFolders
  180.  
  181. if (-not $found -or $found.Count -eq 0) {
  182.     Write-Log "No BattlEye folders found in known locations. You can still run a DRIVER-ONLY reset." "Yellow"
  183. }
  184.  
  185. Write-Host ""
  186. Write-Host "Choose an action:" -ForegroundColor Cyan
  187. Write-Host "  1) Clean SELECTED games (remove BattlEye folder for chosen titles)"
  188. Write-Host "  2) Clean ALL detected games (remove BattlEye across all listed titles)"
  189. Write-Host "  3) QUICK RESET (Driver + AppData only, do NOT touch game folders)"
  190. Write-Host "  4) Exit"
  191. $action = Read-Host "Enter 1-4"
  192.  
  193. switch ($action) {
  194.     "1" {
  195.         if (-not $found -or $found.Count -eq 0) {
  196.             Write-Log "No games to select. Use QUICK RESET (3)." "Red"
  197.             break
  198.         }
  199.  
  200.         Write-Host "`nDetected BattlEye folders:" -ForegroundColor Cyan
  201.         for ($i=0; $i -lt $found.Count; $i++) {
  202.             Write-Host ("  [{0}] {1} - {2}" -f $i, $found[$i].Platform, $found[$i].GameName)
  203.             Write-Host ("       {0}" -f $found[$i].BEPath) -ForegroundColor DarkGray
  204.         }
  205.         $sel = Read-Host "`nEnter comma-separated indexes to clean (e.g. 0,2,3)"
  206.         $idx = $sel -split "," | ForEach-Object { $_.Trim() } | Where-Object { $_ -match '^\d+$' } | ForEach-Object { [int]$_ } | Where-Object { $_ -ge 0 -and $_ -lt $found.Count }
  207.  
  208.         if (-not $idx -or $idx.Count -eq 0) { Write-Log "No valid selection. Aborting." "Yellow"; break }
  209.  
  210.         Write-Log "Running DRIVER RESET first..." "Gray"
  211.         Driver-Reset
  212.  
  213.         foreach ($i in $idx) {
  214.             Write-Log "Removing BattlEye for: $($found[$i].Platform) - $($found[$i].GameName)" "Yellow"
  215.             Remove-Target $found[$i].BEPath
  216.         }
  217.  
  218.         Write-Log "Done. Please VERIFY files in your launcher for the games you cleaned." "Cyan"
  219.     }
  220.     "2" {
  221.         if (-not $found -or $found.Count -eq 0) {
  222.             Write-Log "No games detected. Use QUICK RESET (3)." "Red"
  223.             break
  224.         }
  225.  
  226.         Write-Log "Running DRIVER RESET first..." "Gray"
  227.         Driver-Reset
  228.  
  229.         foreach ($item in $found) {
  230.             Write-Log "Removing BattlEye for: $($item.Platform) - $($item.GameName)" "Yellow"
  231.             Remove-Target $item.BEPath
  232.         }
  233.         Write-Log "Done. Please VERIFY files in your launcher for ALL cleaned games." "Cyan"
  234.     }
  235.     "3" {
  236.         Write-Log "Performing QUICK RESET (Driver + AppData only)..." "Yellow"
  237.         Driver-Reset
  238.         Write-Log "Quick reset complete. Start your game to let BattlEye reinstall, or run a manual verify." "Cyan"
  239.     }
  240.     default {
  241.         Write-Log "Exit." "Gray"
  242.     }
  243. }
  244.  
  245. Write-Log "Script finished."
  246.  
Tags: BEDaisy.sys
Advertisement
Add Comment
Please, Sign In to add comment