Advertisement
DuckStrom

Planetside2 Auto Affinity

Jan 5th, 2020
814
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv
  2. SetTitleMatchMode, 2
  3. #SingleInstance force
  4.  
  5. if (!A_IsAdmin) {
  6.     Run *RunAs "%A_ScriptFullPath%"
  7.     ExitApp
  8. }
  9.  
  10. ShellMessage(wParam, lParam) {
  11.     if (wParam == 0x8004) { ; HSHELL_RUDEAPPACTIVATED
  12.         ; fires every time a window changes focus
  13.         WinGet, currExe, ProcessName, ahk_id %lParam%
  14.         ; ToolTip, % currExe . " " . wParam . " " . lParam . " " . PID
  15.         if (currExe == "PlanetSide2_x64.exe") {
  16.             SoundBeep, 1250, 100
  17.             SoundBeep, 1250, 100
  18.             WinGet, PID, PID, ahk_id %lParam%
  19.             ModProcessAffinityMask(PID, 0xFFFFFFFE)
  20.         }
  21.     }
  22. }
  23.  
  24. ModProcessAffinityMask(PID, BitwiseAnd) {
  25.     if (PID <= 0) {
  26.         return 0
  27.     }
  28.    
  29.     handle := DllCall("OpenProcess"
  30.         , "UInt", 0x1200    ; dwDesiredAccess := PROCESS_QUERY_LIMITED_INFORMATION + PROCESS_SET_INFORMATION
  31.         , "UInt", 0     ; bInheritHandle
  32.         , "UInt", PID)      ; dwProcessId
  33.    
  34.     if (handle == 0) {
  35.         return 0
  36.     }
  37.    
  38.     VarSetCapacity(lpProcessAffinityMask, A_PtrSize)
  39.     VarSetCapacity(lpSystemAffinityMask, A_PtrSize)
  40.    
  41.     result := DllCall("GetProcessAffinityMask"
  42.         , "UPtr", handle
  43.         , "UPtr", &lpProcessAffinityMask
  44.         , "UPtr", &lpSystemAffinityMask)
  45.    
  46.     if (result == 0) {
  47.         DllCall("CloseHandle", "UPtr", handle)
  48.         return 0
  49.     }
  50.    
  51.     lpProcessAffinityMask := NumGet(lpSystemAffinityMask, 0, "UPtr") & BitwiseAnd
  52.     result := DllCall("SetProcessAffinityMask"
  53.         , "UPtr", handle
  54.         , "UPtr", lpProcessAffinityMask)
  55.     ; tooltip, % result . " / " . A_LastError
  56.    
  57.     DllCall("CloseHandle", "UPtr", handle)
  58.     return 1
  59. }
  60.  
  61. Gui +LastFound
  62. hWnd := WinExist()
  63. DllCall("RegisterShellHookWindow", "Ptr", hWnd)
  64. MsgNum := DllCall("RegisterWindowMessage", Str, "SHELLHOOK")
  65. OnMessage(MsgNum, "ShellMessage")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement