Samatter

2ch-tf.au3

Jan 23rd, 2022 (edited)
2,240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 3.48 KB | None | 0 0
  1. #pragma compile(Console, True)
  2. #NoTrayIcon
  3.  
  4. #include <Misc.au3>
  5.  
  6. If (Not @Compiled) Then
  7.     MsgBox(0, "Error", "This script must be compiled to run correctly.")
  8.     Exit
  9. EndIf
  10.  
  11. Global $sConfigPath = @ScriptDir & "\" & StringTrimRight(@ScriptName, 3) & "ini"
  12. Global $sHotKey = IniRead($sConfigPath, "General", "sHotKey", "{Insert}")
  13.  
  14. If HotKeySet($sHotKey, "RunScript") Then
  15.     ConsoleWrite("HotKeySet called and """ & $sHotKey & """ key registered" & @CRLF)
  16. Else
  17.     ConsoleWrite("HotKeySet called but """ & $sHotKey & """ key not registered" & @CRLF)
  18. EndIf
  19.  
  20. Global $hU32 = DllOpen("user32.dll")
  21. Global $bActive = False
  22.  
  23. While True
  24.     Sleep(1000)
  25. WEnd
  26.  
  27. Func RunScript()
  28.     $bActive = Not $bActive
  29.     If $bActive Then
  30.         ConsoleWrite("RunScript called, bActive is TRUE" & @CRLF)
  31.         Local $iLinesCount = IniRead($sConfigPath, "General", "iLinesCount", 0)
  32.         If ($iLinesCount > 0) Then
  33.             ConsoleWrite("iLinesCount is " & $iLinesCount & ", triforce started" & @CRLF)
  34.             DrawTF($iLinesCount)
  35.         EndIf
  36.         $bActive = False
  37.         ConsoleWrite("Triforce completed, you can use """ & $sHotKey & """ key again" & @CRLF)
  38.     EndIf
  39. EndFunc
  40.  
  41. Func StopScript()
  42.     If $bActive Then
  43.         ConsoleWrite("StopScript called, bActive is TRUE, triforce canceled" & @CRLF)
  44.         DllClose($hU32)
  45.         $bActive = False
  46.         HotKeySet($sHotKey)
  47.         Run(@ScriptFullPath)
  48.         Exit
  49.     Else
  50.         ConsoleWrite("StopScript called, but bActive is FALSE, do nothing" & @CRLF)
  51.     EndIf
  52. EndFunc
  53.  
  54. Func DrawTF($iCount)
  55.     ; read settings
  56.     Local $sPrefixSpaceB64 = IniRead($sConfigPath, "Symbols", "sPrefixSpaceB64", "")
  57.     Local $sMainSymbolB64 = IniRead($sConfigPath, "Symbols", "sMainSymbolB64", "")
  58.     Local $sMainSpaceB64 = IniRead($sConfigPath, "Symbols", "sMainSpaceB64", "")
  59.     ; decode from base64
  60.     Local $sPrefixSpace = Base64ToUTF8($sPrefixSpaceB64)
  61.     Local $sMainSymbol = Base64ToUTF8($sMainSymbolB64)
  62.     Local $sMainSpace = Base64ToUTF8($sMainSpaceB64)
  63.     ; combine main chunk
  64.     Local $sMainChunk = $sMainSpace & $sMainSymbol
  65.     ; send text into lines
  66.     For $iLineIndex = 1 To $iCount Step 1
  67.         If IsEscPressed($hU32) Then
  68.             StopScript()
  69.         Else
  70.             Local $sPrefix = TextMult($sPrefixSpace, $iCount - $iLineIndex)
  71.             Local $sMain = $sMainSymbol & TextMult($sMainChunk, $iLineIndex - 1)
  72.             Send($sPrefix & $sMain & "{ENTER}")
  73.         EndIf
  74.     Next
  75.     Send("{BACKSPACE}")
  76. EndFunc
  77.  
  78. Func TextMult($sText, $iMult)
  79.     Local $sResult = ""
  80.     For $iIndex = 1 To $iMult Step 1
  81.         $sResult = $sResult & $sText
  82.     Next
  83.     Return $sResult
  84. EndFunc
  85.  
  86. Func Base64ToUTF8($sInput)
  87.     If (Not $sInput) Then Return ""
  88.     ; 1st pass - calculate size
  89.     Local $StructA = DllStructCreate("int")
  90.     Local $StructA_PTR = DllStructGetPtr($StructA)
  91.     Local $CallA = DllCall("crypt32.dll", "int", "CryptStringToBinary", "str", $sInput, "int", 0, "int", 1, "ptr", 0, "ptr", $StructA_PTR, "ptr", 0, "ptr", 0)
  92.     If @error Or (Not $CallA[0]) Then Return ""
  93.     ; 2nd pass - perform conversion
  94.     Local $StructB = DllStructCreate("byte[" & DllStructGetData($StructA, 1) & "]")
  95.     Local $StructB_PTR = DllStructGetPtr($StructB)
  96.     Local $CallB = DllCall("crypt32.dll", "int", "CryptStringToBinary", "str", $sInput, "int", 0, "int", 1, "ptr", $StructB_PTR, "ptr", $StructA_PTR, "ptr", 0, "ptr", 0)
  97.     If @error Or (Not $CallB[0]) Then Return ""
  98.     ; return result
  99.     Return BinaryToString(DllStructGetData($StructB, 1), 4)
  100. EndFunc
  101.  
  102. Func IsEscPressed($hDLL)
  103.     Local $Call = DllCall($hDLL, "short", "GetAsyncKeyState", "int", "0x1B")
  104.     If @error Then Return SetError(@error, @extended, False)
  105.     Return BitAND($Call[0], 0x8000) <> 0
  106. EndFunc
Add Comment
Please, Sign In to add comment