Created
February 17, 2024 19:09
-
-
Save spddl/d468279dc4853c3995646615576b7669 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Automation of this guide: | |
# https://www.reddit.com/r/cs2/comments/1apx40j/comment/kq9ay6u | |
# from u/El_Chapaux | |
Function Get-FileSize { | |
Param( | |
$length | |
) | |
If ($length -ge 1TB) { | |
return '{0:N2} TB' -f ($length / 1TB) | |
} elseif ($length -ge 1GB) { | |
return '{0:N2} GB' -f ($length / 1GB) | |
} elseif ($length -ge 1MB) { | |
return '{0:N2} MB' -f ($length / 1MB) | |
} elseif ($length -ge 1KB) { | |
return '{0:N2} KB' -f ($length / 1KB) | |
} else { | |
return "$length bytes" | |
} | |
} | |
Function Clear-Folder { | |
Param( | |
[string]$path | |
) | |
if (-Not (Test-Path -Path $path)) { | |
$nul = Get-FileSize(0) | |
return [pscustomobject]@{path = $path; 'before cleaning' = $nul; afterwards = $nul; deleted = $nul } | |
} | |
[int64]$beforeLength = 0 | |
Get-ChildItem -Path $path -Recurse -Force | ForEach-Object { | |
$beforeLength += $_.Length | |
} | |
If ($beforeLength -eq 0) { | |
$nul = Get-FileSize(0) | |
return [pscustomobject]@{path = $path; 'before cleaning' = $nul; afterwards = $nul; deleted = $nul } | |
} | |
Remove-Item -Path $path -Recurse -Force -ErrorAction SilentlyContinue | |
[int64]$afterwardsLength = 0 | |
Get-ChildItem -Path $path -Recurse -Force | ForEach-Object { | |
$afterwardsLength += $_.Length | |
} | |
[pscustomobject]@{path = $path; 'before cleaning' = Get-FileSize($beforeLength); afterwards = Get-FileSize($afterwardsLength); deleted = Get-FileSize($beforeLength - $afterwardsLength) } | |
} | |
Function Clear-Files { | |
Param( | |
[string]$path | |
) | |
[int64]$beforeLength = 0 | |
Get-ChildItem -Path $path -Force -ErrorAction SilentlyContinue | ForEach-Object { | |
$beforeLength += $_.Length | |
Remove-Item -LiteralPath $_.FullName -Force -ErrorAction SilentlyContinue | |
} | |
If ($beforeLength -eq 0) { | |
$nul = Get-FileSize(0) | |
return [pscustomobject]@{path = $path; 'before cleaning' = $nul; afterwards = $nul; deleted = $nul } | |
} | |
Remove-Item -Path $path -Force -ErrorAction SilentlyContinue | |
[int64]$afterwardsLength = 0 | |
Get-ChildItem -Path $path -Force | ForEach-Object { | |
$afterwardsLength += $_.Length | |
} | |
[pscustomobject]@{path = $path; 'before cleaning' = Get-FileSize($beforeLength); afterwards = Get-FileSize($afterwardsLength); deleted = Get-FileSize($beforeLength - $afterwardsLength) } | |
} | |
$SteamPath = (Get-ItemProperty -Path HKCU:\SOFTWARE\Valve\Steam -Name SteamPath).SteamPath | |
$libraryfolders = [IO.Path]::Combine($SteamPath , 'steamapps', 'libraryfolders.vdf') | |
$path = '' | |
$SteamFolder = Get-Content $libraryfolders | ForEach-Object { | |
if ($_ -match '("path").*"(.+)"') { | |
$path = $Matches[2] | |
} | |
if ($_ -match '("730").*"(.+)"') { | |
return $path | Resolve-Path | |
} | |
} | |
$csgoFolder = [IO.Path]::Combine($SteamFolder, 'steamapps', 'common', 'Counter-Strike Global Offensive') | |
Get-ChildItem -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches -Exclude 'Device Driver Packages' | ForEach-Object { | |
if ($_.Property -NotContains 'StateFlags') { | |
return | |
} | |
if ($_.Property -NotContains 'StateFlags1337') { | |
if ($_.PSChildName -eq 'D3D Shader Cache') { | |
New-ItemProperty -Path $_.PSPath -Name 'StateFlags1337' -Value '2' -PropertyType DWord | Out-Null | |
} else { | |
New-ItemProperty -Path $_.PSPath -Name 'StateFlags1337' -Value '0' -PropertyType DWord | Out-Null | |
} | |
} | |
} | |
######## | |
# delete the DirectX Shader Cache | |
# https://learn.microsoft.com/de-de/troubleshoot/windows-server/backup-and-storage/automating-disk-cleanup-tool#registry-key-information | |
Start-Process -FilePath cleanmgr.exe -ArgumentList '/sagerun:1337' | |
@( | |
Clear-Folder("C:\Users\$([Environment]::UserName)\AppData\LocalLow\NVIDIA\PerDriverVersion\DXCache") | |
Clear-Folder("C:\Users\$([Environment]::UserName)\AppData\Local\NVIDIA\GLCache") | |
Clear-Files("$csgoFolder\game\bin\win64\*.mdmp") | |
Clear-Files("$csgoFolder\game\csgo\*.txt") | |
Clear-Files("$csgoFolder\game\csgo\*.log") | |
) | |
# Verify integrity of game files | |
Start-Process 'steam://validate/730' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment