Advertisement
Guest User

Untitled

a guest
Aug 11th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #WinActivateForce
  2. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  3. #SingleInstance, Force
  4. SetBatchLines, -1
  5.  
  6. ;Install all images inside the exe/ahk file
  7. FileInstall, Dark_ChatOptions_A.png, %A_ScriptFullPath%:Dark_ChatOptions_A.png
  8. FileInstall, Dark_ChatOptions_B.png, %A_ScriptFullPath%:Dark_ChatOptions_B.png
  9. FileInstall, Light_ChatOptions_A.png, %A_ScriptFullPath%:Light_ChatOptions_A.png
  10. FileInstall, Light_ChatOptions_B.png, %A_ScriptFullPath%:Light_ChatOptions_B.png
  11. FileInstall, Dark_Discord_Logo.png, %A_ScriptFullPath%:Dark_Discord_Logo.png
  12. FileInstall, Dark_Discord_LogoB.png, %A_ScriptFullPath%:Dark_Discord_LogoB.png
  13. FileInstall, Dark_Discord_LogoC.png, %A_ScriptFullPath%:Dark_Discord_LogoC.png
  14. FileInstall, Loading_Messages.png, %A_ScriptFullPath%:Loading_Messages.png
  15.  
  16. global Process_id := ""
  17. global CurrentTask := "Starting Up"
  18.  
  19. ;Set Process_id globals and maximize the window
  20. f1::
  21.     System_CheckWindowsList()
  22.    
  23. return
  24. ;Find the discord logo!
  25. f2::
  26.  
  27.     System_FullScreen_Scan("Dark_Discord_Logo")
  28.     System_FullScreen_Scan("Dark_Discord_LogoB")
  29.     System_FullScreen_Scan("Dark_Discord_LogoC")
  30. return
  31.  
  32. ;Look for some options
  33. f3::
  34.     Random, v, 0, 100
  35.     MouseMove, (A_ScreenWidth/2), ((A_ScreenHeight/2)+v), 0
  36.     Sleep, 50
  37.     System_FullScreen_Scan("Light_ChatOptions_A")
  38.     System_FullScreen_Scan("Dark_ChatOptions_A")
  39.    
  40.     System_FullScreen_Scan("Light_ChatOptions_B")
  41.     System_FullScreen_Scan("Dark_ChatOptions_B")
  42. return
  43.  
  44. ;Start recursive check
  45. f4::
  46.     SetTimer, FidelityScanner, 100
  47. return
  48.  
  49. ^!p::
  50. Send {PrintScreen}
  51. Run MSPaint
  52. WinWait, Untitled - Paint
  53. Sleep, 100
  54. Send, {CTRLDOWN}v{CTRLUP}
  55. return
  56.  
  57.  
  58.  
  59.  
  60. return
  61.  
  62. FidelityScanner:
  63.     ImageFile = %A_ScriptFullPath%:Dark_Discord_Logo.png
  64.     ImageSearch, OutputVarX, OutputVarY, 0, 0, A_ScreenWidth, A_ScreenHeight, %A_ScriptFullPath%:Dark_Discord_Logo.png
  65.     ImageSearch, OutputVarXX, OutputVarYY, 0, 0, A_ScreenWidth, A_ScreenHeight, %A_ScriptFullPath%:Dark_Discord_LogoB.png
  66.     ImageSearch, OutputVarXXX, OutputVarYYY, 0, 0, A_ScreenWidth, A_ScreenHeight, %A_ScriptFullPath%:Dark_Discord_LogoC.png
  67.     if (OutputVarX OR OutputVarXX OR OutputVarXXX)
  68.     {
  69.         ToolTip, Fidelity: Positive `n%CurrentTask%
  70.         WinGetTitle WinTitle, ahk_id %Process_id%
  71.         WinGetPos, X, Y, Width, Height, %WinTitle%,,,
  72.         ;MsgBox, X: %X% Y: %Y% Width: %Width% Height: %Height%
  73.         ;MsgBox, . (%(%-%Width%) . (%A_ScreenHeight%-%Height%)  
  74.         if ((A_ScreenWidth-Width) > 100) OR ((A_ScreenHeight-Height) > 100)
  75.         {
  76.             ;MsgBox, Out of size range!
  77.             WinGetTitle wt, ahk_id %Process_id%
  78.             WinActivate, %wt%
  79.             WinMaximize, %wt%
  80.         }
  81.     }
  82.     else
  83.     {
  84.         Loop 6
  85.         {
  86.             ;break
  87.             CurrentTask := "Rescuing Target... " (6-A_Index)
  88.             ToolTip, Fidelity: Negative `n%CurrentTask%
  89.             Sleep, 1000
  90.             ImageSearch, OutputVarX, OutputVarY, 0, 0, A_ScreenWidth, A_ScreenHeight, %A_ScriptFullPath%:Dark_Discord_Logo.png
  91.             ImageSearch, OutputVarXX, OutputVarYY, 0, 0, A_ScreenWidth, A_ScreenHeight, %A_ScriptFullPath%:Dark_Discord_LogoB.png
  92.             ImageSearch, OutputVarXXX, OutputVarYYY, 0, 0, A_ScreenWidth, A_ScreenHeight, %A_ScriptFullPath%:Dark_Discord_LogoC.png
  93.             if (OutputVarX OR OutputVarXX OR OutputVarXXX)
  94.             {
  95.                 CurrentTask := "Waiting..."
  96.                 return
  97.             }
  98.            
  99.         }
  100.         CurrentTask := "Waiting..."
  101.         System_CheckWindowsList()
  102.         ToolTip, Fidelity: Negative `n%CurrentTask%
  103.         Sleep, 1000
  104.     }
  105. return
  106. ;This finds the path of the process executable
  107. GetModuleExeName(p_id) {
  108.     for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process where ProcessId=" p_id)
  109.         return process.ExecutablePath
  110. }
  111.  
  112. System_CheckWindowsList()
  113. {
  114.     ;This is the 'soft' check for discord simply cycling the windows that are open
  115.     DetectHiddenWindows, Off
  116.     WinGet windows, List
  117.     Loop %windows%
  118.     {
  119.         Process_id := windows%A_Index%
  120.         WinGetTitle wt, ahk_id %Process_id%
  121.         WinGet, PName, ProcessName, %wt%,,,
  122.        
  123.         r .= wt . id . PName . "`n"
  124.        
  125.         if PName = Discord.exe
  126.         {
  127.             ;MsgBox, Got it!
  128.             WinGetTitle wt, ahk_id %Process_id%
  129.             WinActivate, %wt%
  130.             WinMaximize, %wt%
  131.             return
  132.         }
  133.     }
  134.     ;This is the 'hard' check for discord that checks for 'hidden' (windows does this behaviour for tray icon minimizing and other stuff)
  135.     ;Once it finds the first hidden EXE it finds the file path and executes it. Discord only allows one instance to run so it's a trick to open it up from the tray
  136.     DetectHiddenWindows, On
  137.     WinGet windows, List
  138.     Loop %windows%
  139.     {
  140.         Process_id := windows%A_Index%
  141.         WinGetTitle wt, ahk_id %Process_id%
  142.         WinGet, PName, ProcessName, %wt%,,,
  143.        
  144.         ;r .= wt . id . PName . "`n"
  145.        
  146.         if PName = Discord.exe
  147.         {
  148.             WinGet, PID, PID, ahk_id %Process_id%
  149.             FullEXEPath := GetModuleExeName(PID)
  150.             ;Remove the exe from the path name
  151.             FullEXEPath := StrReplace(FullEXEPath, PName, "")
  152.             ;MsgBox, Found it! %wt% `n %PName% `n %FullEXEPath% %PID%
  153.                
  154.             Run, %PName%, %FullEXEPath%,
  155.             WinMaximize, %wt%
  156.             ;WinWait, %wt%
  157.             ;WinShow, Spark ahk_pid %SparkVar%
  158.             ;WinShow,%wt%,,,
  159.             ;WinActivate, %wt%,,,
  160.             break
  161.         }
  162.     }
  163.     ;MsgBox %r%
  164. }
  165.  
  166. System_SetDimensions()
  167. {
  168.     Ratio := A_ScreenWidth / A_ScreenHeight
  169.  
  170.     MsgBox, Ratio: %Ratio% Width: %A_ScreenWidth% Height %A_ScreenHeight%
  171. }
  172. ;Scan the whole screen, move mouse to position
  173. System_FullScreen_Scan(Img)
  174. {
  175.     ImageFile = %A_ScriptFullPath%:%Img%.png
  176.     ImageSearch, OutputVarX, OutputVarY, 0, 0, A_ScreenWidth, A_ScreenHeight, %ImageFile%
  177.    
  178.     if OutputVarX
  179.     {
  180.         ToolTip, Found! `n %Img%
  181.         Sleep, 100
  182.         MouseMove, OutputVarX, OutputVarY, 75
  183.     }
  184.     else
  185.     {
  186.        
  187.     }
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement