Skip to content

Instantly share code, notes, and snippets.

@Philmist
Created December 24, 2019 06:00
Show Gist options
  • Save Philmist/8510a95b733cf02f465b0e0d308dad16 to your computer and use it in GitHub Desktop.
Save Philmist/8510a95b733cf02f465b0e0d308dad16 to your computer and use it in GitHub Desktop.
Set affinity of target process (Escape of Tarkov)
# Path to Launcher
$ExecuteTarget = "C:\Games\Battlestate Games\BsgLauncher\BsgLauncher.exe"
# Target process to set affinity
$TargetProcess = "EscapeFromTarkov"
# Get Number of cpu's physical core
$PhysicalCores = 0
(Get-WmiObject Win32_Processor).NumberOfCores | %{ $PhysicalCores += $_ }
# Start launcher
Write-Host "Starting up : " $ExecuteTarget
Start-Process -FilePath $ExecuteTarget
# Wait for starting up process
Write-Host "Wait for starting : " $TargetProcess
$Awake = $false
while($Awake -ne $false) {
try {
Get-Process -Name $TargetProcess -ErrorAction Stop
} catch {
if ($_.exception -is [Microsoft.PowerShell.Commands.ProcessCommandException]) {
Start-Sleep -Seconds 5
continue
} else {
throw $_.exception
}
}
$Awake = $true
}
Write-Host "Started."
# Calculate affinity from number of physical core(s)
$TargetAffinity = 0
for ($i = ($PhysicalCores - 1); $i -ge 0; $i--) {
$TargetAffinity = $TargetAffinity -bor (1 -shl ($i * 2))
}
Write-Host "Target affinity is " $TargetAffinity
# Set process affinity and priority (loop)
while($true) {
Start-Sleep -Seconds 60
try {
$Process = Get-Process -Name $TargetProcess
$Process.ProcessorAffinity = $TargetAffinity
$Process.PriorityClass = [System.Diagnostics.ProcessPriorityClass]::AboveNormal
Write-Host $Process.Name " : Affinity " $Process.ProcessorAffinity
} catch {
break
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment