Advertisement
darklinkpower

Untitled

Jan 22nd, 2022
1,711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Start-SpecialkService
  2. {
  3.     param(
  4.         $cpuArchitecture,
  5.         $skifPath
  6.     )
  7.    
  8.     $dllPath = [System.IO.Path]::Combine($skifPath, "SpecialK" + $cpuArchitecture + ".dll")
  9.     if ([System.IO.File]::Exists($dllPath) -eq $false)
  10.     {
  11.         $__logger.Info("Special K dll not found in $dllPath")
  12.         return $false
  13.     }
  14.  
  15.     $serviceParams = @{
  16.         FilePath = "rundll32.exe"
  17.         ArgumentList = "`"$dllPath`",RunDLL_InjectionManager Install"
  18.         WorkingDirectory = $skifPath
  19.         Wait = $false
  20.     }
  21.     Start-Process @serviceParams
  22.  
  23.     $eventName = "Local\SK_GlobalHookTeardown" + $cpuArchitecture
  24.     $i = 0
  25.     do
  26.     {
  27.         try {
  28.             Start-Sleep -Milliseconds 100
  29.             $eventWaitHandle = [System.Threading.EventWaitHandle]::OpenExisting($eventName)
  30.             $eventWaitHandle.Close()
  31.             $eventWaitHandle.Dispose()
  32.             $__logger.Info("Special K process and event for $dllPath started")
  33.             return $true
  34.         } catch {
  35.             $i++
  36.             Start-Sleep -Milliseconds 300
  37.         }
  38.     } while ($i -lt 10)
  39.  
  40.     $__logger.Info("Special K event `"$eventName`" could not be opened")
  41.     return $false
  42. }
  43.  
  44. function Stop-SpecialkService
  45. {
  46.     param(
  47.         $cpuArchitecture,
  48.         $skifPath
  49.     )
  50.    
  51.     $dllPath = [System.IO.Path]::Combine($skifPath, "SpecialK" + $cpuArchitecture + ".dll")
  52.     if ([System.IO.File]::Exists($dllPath) -eq $false)
  53.     {
  54.         $__logger.Info("Special K dll not found in $dllPath")
  55.         return $false
  56.     }
  57.    
  58.     try {
  59.         $serviceParams = @{
  60.             FilePath = "rundll32.exe"
  61.             ArgumentList = "`"$dllPath`",RunDLL_InjectionManager Remove"
  62.             WorkingDirectory = $skifPath
  63.             Wait = $false
  64.         }
  65.         Start-Process @serviceParams
  66.         $__logger.Info("Special K $cpuArchitecture service has been removed")
  67.         return $true
  68.     } catch {
  69.         $__logger.Info("Special K $cpuArchitecture service could not be removed")
  70.         return $false
  71.     }
  72. }
  73.  
  74. function OnGameStarting
  75. {
  76.     param(
  77.         $OnGameStartingEventArgs
  78.     )
  79.    
  80.     $game = $OnGameStartingEventArgs.Game
  81.    
  82.     $skifPath = [System.IO.Path]::Combine([Environment]::GetFolderPath("MyDocuments"), "My Mods", "SpecialK")
  83.     $cpuArchitectures = @("32", "64")
  84.  
  85.     $disableSpecialK = $false
  86.     if ($game.Features)
  87.     {
  88.         foreach ($feature in $game.Features)
  89.         {
  90.             if (($feature.Name -eq "[SW] Disable Special K") -or ($feature.Name -eq "Valve Anti-Cheat Enabled"))
  91.             {
  92.                 $disableSpecialK = $true
  93.                 $__logger.Info("`"Disable Special K`" feature found. Special K will be disabled.")
  94.                 break
  95.             }
  96.         }
  97.     }
  98.    
  99.     foreach ($cpuArchitecture in $cpuArchitectures)
  100.     {
  101.         if ($disableSpecialK -eq $true)
  102.         {
  103.             # Check if leftover service is running and close it
  104.             Stop-SpecialkService $cpuArchitecture $skifPath
  105.         }
  106.         else
  107.         {
  108.             if ($null -eq $game.Platforms)
  109.             {
  110.                 $__logger.Info("Null platforms")
  111.                 return
  112.             }
  113.            
  114.             if ($null -eq ($game.Platforms | Where-Object {$_.Name -eq "PC (Windows)"}))
  115.             {
  116.                 $__logger.Info("Not a PC game")
  117.                 return
  118.             }
  119.  
  120.             Start-SpecialkService $cpuArchitecture $skifPath
  121.         }
  122.     }
  123. }
  124.  
  125. function OnGameStopped
  126. {
  127.     param(
  128.         $OnGameStoppedEventArgs
  129.     )
  130.    
  131.     $skifPath = [System.IO.Path]::Combine([Environment]::GetFolderPath("MyDocuments"), "My Mods", "SpecialK")
  132.     $cpuArchitectures = @("32", "64")
  133.     foreach ($cpuArchitecture in $cpuArchitectures)
  134.     {
  135.         Stop-SpecialkService $cpuArchitecture $skifPath
  136.     }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement