Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Start-SpecialkService
- {
- param(
- $cpuArchitecture,
- $skifPath
- )
- $dllPath = [System.IO.Path]::Combine($skifPath, "SpecialK" + $cpuArchitecture + ".dll")
- if ([System.IO.File]::Exists($dllPath) -eq $false)
- {
- $__logger.Info("Special K dll not found in $dllPath")
- return $false
- }
- $serviceParams = @{
- FilePath = "rundll32.exe"
- ArgumentList = "`"$dllPath`",RunDLL_InjectionManager Install"
- WorkingDirectory = $skifPath
- Wait = $false
- }
- Start-Process @serviceParams
- $eventName = "Local\SK_GlobalHookTeardown" + $cpuArchitecture
- $i = 0
- do
- {
- try {
- Start-Sleep -Milliseconds 100
- $eventWaitHandle = [System.Threading.EventWaitHandle]::OpenExisting($eventName)
- $eventWaitHandle.Close()
- $eventWaitHandle.Dispose()
- $__logger.Info("Special K process and event for $dllPath started")
- return $true
- } catch {
- $i++
- Start-Sleep -Milliseconds 300
- }
- } while ($i -lt 10)
- $__logger.Info("Special K event `"$eventName`" could not be opened")
- return $false
- }
- function Stop-SpecialkService
- {
- param(
- $cpuArchitecture,
- $skifPath
- )
- $dllPath = [System.IO.Path]::Combine($skifPath, "SpecialK" + $cpuArchitecture + ".dll")
- if ([System.IO.File]::Exists($dllPath) -eq $false)
- {
- $__logger.Info("Special K dll not found in $dllPath")
- return $false
- }
- try {
- $serviceParams = @{
- FilePath = "rundll32.exe"
- ArgumentList = "`"$dllPath`",RunDLL_InjectionManager Remove"
- WorkingDirectory = $skifPath
- Wait = $false
- }
- Start-Process @serviceParams
- $__logger.Info("Special K $cpuArchitecture service has been removed")
- return $true
- } catch {
- $__logger.Info("Special K $cpuArchitecture service could not be removed")
- return $false
- }
- }
- function OnGameStarting
- {
- param(
- $OnGameStartingEventArgs
- )
- $game = $OnGameStartingEventArgs.Game
- $skifPath = [System.IO.Path]::Combine([Environment]::GetFolderPath("MyDocuments"), "My Mods", "SpecialK")
- $cpuArchitectures = @("32", "64")
- $disableSpecialK = $false
- if ($game.Features)
- {
- foreach ($feature in $game.Features)
- {
- if (($feature.Name -eq "[SW] Disable Special K") -or ($feature.Name -eq "Valve Anti-Cheat Enabled"))
- {
- $disableSpecialK = $true
- $__logger.Info("`"Disable Special K`" feature found. Special K will be disabled.")
- break
- }
- }
- }
- foreach ($cpuArchitecture in $cpuArchitectures)
- {
- if ($disableSpecialK -eq $true)
- {
- # Check if leftover service is running and close it
- Stop-SpecialkService $cpuArchitecture $skifPath
- }
- else
- {
- if ($null -eq $game.Platforms)
- {
- $__logger.Info("Null platforms")
- return
- }
- if ($null -eq ($game.Platforms | Where-Object {$_.Name -eq "PC (Windows)"}))
- {
- $__logger.Info("Not a PC game")
- return
- }
- Start-SpecialkService $cpuArchitecture $skifPath
- }
- }
- }
- function OnGameStopped
- {
- param(
- $OnGameStoppedEventArgs
- )
- $skifPath = [System.IO.Path]::Combine([Environment]::GetFolderPath("MyDocuments"), "My Mods", "SpecialK")
- $cpuArchitectures = @("32", "64")
- foreach ($cpuArchitecture in $cpuArchitectures)
- {
- Stop-SpecialkService $cpuArchitecture $skifPath
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement