lyzing

ThunderSwitch

Oct 13th, 2020
2,422
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #RequireAdmin
  2. #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
  3. #AutoIt3Wrapper_Icon=main.ico
  4. #AutoIt3Wrapper_Outfile=ThunderSwitch.exe
  5. #AutoIt3Wrapper_UseUpx=n
  6. #AutoIt3Wrapper_UseX64=n
  7. #AutoIt3Wrapper_Res_Fileversion=1.0.0.0
  8. #AutoIt3Wrapper_Res_LegalCopyright=Paraly
  9. #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
  10. Global $GPU = False, $GPU_Cache = -1, $GPU_Name = "", $GPU_Mode = "IGPU", $Paused = False, $FirstStart = False
  11. $CheckGPUState_Timer = TimerInit()
  12.  
  13. Opt("TrayMenuMode", 1 + 2)
  14. Global $TRAY_Status = TrayCreateItem("Current Mode = ")
  15. TrayCreateItem("")
  16. Global $TRAY_Pause = TrayCreateItem("Pause")
  17. Global $TRAY_Exit = TrayCreateItem("Exit")
  18. TraySetToolTip("ThunderSwitch")
  19.  
  20. _LogWrite("=================" & @CRLF,1)
  21. _LogWrite("Startup...")
  22.  
  23. AdlibRegister("_TrayMSG", 150)
  24.  
  25. If FileExists(@ScriptDir & "\config.ini") = 0 Then
  26.     $f = FileOpen(@ScriptDir & "\config.ini",10)
  27.     FileWrite($f,"[Settings]" & @CRLF & "RunOnStartup=" & @CRLF & @CRLF & "[Gamelist]" & @CRLF & "File_1=DragonQuestXI_GameUserSettings.ini" & @CRLF & "Path_1=C:\Users\ParalyMax\Documents\my games\DRAGON QUEST XI\Saved\Config\WindowsNoEditor\GameUserSettings.ini" & @CRLF & "File_2=Borderlands3_GameUserSettings.ini" & @CRLF & "Path_2=C:\Users\ParalyMax\Documents\my games\Borderlands 3\Saved\Config\WindowsNoEditor\GameUserSettings.ini" & @CRLF & "File_3=MonsterHunterWorld_graphics_option.ini" & @CRLF & "Path_3=C:\Program Files (x86)\Steam\steamapps\common\Monster Hunter World\graphics_option.ini")
  28.     FileClose($f)
  29.     $FirstStart = True
  30. EndIf
  31. If FileExists(@ScriptDir & "\EGPU") = 0 Then
  32.     DirCreate(@ScriptDir & "\EGPU")
  33. EndIf
  34. If FileExists(@ScriptDir & "\IGPU") = 0 Then
  35.     DirCreate(@ScriptDir & "\IGPU")
  36. EndIf
  37. If $FirstStart = True Then
  38.     MsgBox(0,"ThunderSwitch","config.ini file got created" & @CRLF & "You've to copy setting files into the EGPU and IGPU folders and then declare them at the config.ini" & @CRLF & "The config.ini file expects the file name within the EGPU/IGPU folder and the full path it should copy it to, a few example lines got added")
  39. EndIf
  40.  
  41. If IniRead(@ScriptDir & "\config.ini","Settings","RunOnStartup","") <> "" Then
  42.     _LogWrite("Starting [" & IniRead(@ScriptDir & "\config.ini","Settings","RunOnStartup",-1) & "]")
  43.     Run(IniRead(@ScriptDir & "\config.ini","Settings","RunOnStartup",-1))
  44. EndIf
  45.  
  46.  
  47. While 1
  48.     If TimerDiff($CheckGPUState_Timer) > 750 Then
  49.         $GPU = _CheckGPUState()
  50.         If $GPU <> $GPU_Cache Then
  51.             _LogWrite("GPU Switched to " & $GPU_Name)
  52.             _ApplySettings($GPU)
  53.             $GPU_Cache = $GPU
  54.         EndIf
  55.  
  56.         If $GPU = True Then
  57.             $GPU_Mode = "EGPU"
  58.         ElseIf $GPU = False Then
  59.             $GPU_Mode = "IGPU"
  60.         EndIf
  61.         TrayItemSetText($TRAY_Status,"Current Mode = " & $GPU_Mode)
  62.         $CheckGPUState_Timer = TimerInit()
  63.     EndIf
  64.     Sleep(50)
  65. WEnd
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74. Func _ApplySettings($mode)
  75.     If $mode = False Then; IGPU
  76.         _LogWrite("Applying IGPU Settings...")
  77.         $CopyError = 0
  78.         $CopySuccess = 0
  79.         For $i = 1 To 2000
  80.             $t_File = IniRead(@ScriptDir & "\config.ini","Gamelist","File_" & $i,-1)
  81.             $t_Path = IniRead(@ScriptDir & "\config.ini","Gamelist","Path_" & $i,-1)
  82.             If $t_File <> -1 And $t_Path <> -1 Then
  83.                 If FileCopy(@ScriptDir & "\IGPU\" & $t_File, $t_Path,9) <> 1 Then
  84.                     $CopyError += 1
  85.                 Else
  86.                     $CopySuccess += 1
  87.                 EndIf
  88.             Else
  89.                 ExitLoop
  90.             EndIf
  91.         Next
  92.         _LogWrite($CopySuccess & " IGPU Settings Applied (" & $CopyError & " Errors)")
  93.     ElseIf $mode = True Then; EGPU
  94.         _LogWrite("Applying EGPU Settings...")
  95.         $CopyError = 0
  96.         $CopySuccess = 0
  97.         For $i = 1 To 2000
  98.             $t_File = IniRead(@ScriptDir & "\config.ini","Gamelist","File_" & $i,-1)
  99.             $t_Path = IniRead(@ScriptDir & "\config.ini","Gamelist","Path_" & $i,-1)
  100.             If $t_File <> -1 And $t_Path <> -1 Then
  101.                 If FileCopy(@ScriptDir & "\EGPU\" & $t_File, $t_Path,9) <> 1 Then
  102.                     $CopyError += 1
  103.                 Else
  104.                     $CopySuccess += 1
  105.                 EndIf
  106.             Else
  107.                 ExitLoop
  108.             EndIf
  109.         Next
  110.         _LogWrite($CopySuccess & " EGPU Settings Applied (" & $CopyError & " Errors)")
  111.     EndIf
  112. EndFunc
  113.  
  114.  
  115. Func _LogWrite($tString,$mode = 0)
  116.     If FileExists(@ScriptDir & "\log.txt") = 0 Then
  117.         $tf = FileOpen(@ScriptDir & "\log.txt",10)
  118.         FileClose($tf)
  119.     EndIf
  120.     $f = FileOpen(@ScriptDir & "\log.txt",1)
  121.     If $mode = 0 Then
  122.         FileWrite($f,@MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " -- " & $tString & @CRLF)
  123.     ElseIf $mode = 1 Then
  124.         FileWrite($f,$tString)
  125.     EndIf
  126.     FileClose($f)
  127. EndFunc
  128.  
  129.  
  130. Func _CheckGPUState()
  131.     $objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
  132.     $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DisplayConfiguration", "WQL", 0x10 + 0x20)
  133.     If IsObj($colItems) then
  134.        For $objItem In $colItems
  135.             $GPU_Name = $objItem.DeviceName
  136.        Next
  137.     Endif
  138.  
  139.     If StringRegExp($GPU_Name,"(?i)Intel",0) = 1 Then
  140.         Return False
  141.     Else
  142.         Return True
  143.     EndIf
  144. EndFunc
  145.  
  146.  
  147. Func _TrayMSG()
  148.     Local $msg = TrayGetMsg()
  149.     Select
  150.         Case $msg = $TRAY_Status
  151.             $t = MsgBox(4,"ThunderSwitch", "Re-apply " & $GPU_Mode & " Settings?")
  152.             If $t = 6 Then
  153.                 _ApplySettings($GPU)
  154.             EndIf
  155.         Case $msg = $TRAY_Pause
  156.             $Paused = Not $Paused
  157.             If $Paused = True Then
  158.                 _LogWrite("Toggled Pause ON")
  159.                 While $Paused = True
  160.                     Local $msg = TrayGetMsg()
  161.                     Select
  162.                         Case $msg = $TRAY_Pause
  163.                             _LogWrite("Toggled Pause OFF")
  164.                             $Paused = False
  165.                         Case $msg = $TRAY_Exit
  166.                             _LogWrite("Exiting...")
  167.                             _LogWrite("=================" & @CRLF,1)
  168.                             Exit
  169.                     EndSelect
  170.                 WEnd
  171.             EndIf
  172.         Case $msg = $TRAY_Exit
  173.             _LogWrite("Exiting...")
  174.             _LogWrite("=================" & @CRLF,1)
  175.             Exit
  176.     EndSelect
  177. EndFunc
  178.  
RAW Paste Data