Skip to content

Commit

Permalink
Add config options
Browse files Browse the repository at this point in the history
  • Loading branch information
Luashine committed Nov 14, 2022
1 parent c431479 commit bc67504
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.ini
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ print("x + y = ".. x + y)
- Warns about lines too long for chat (max: 127 characters)
- Audio indicators
- Restores your clipboard after pasting in WC3
- Configurable
- Probably many false-positives by anti-virus software (complain to them about it)
- Why? AutoIt was used by scriptkiddies in the past, but it doesn't excuse
a blanket ban that flags ALL au3 scripts as malware.
Expand Down
42 changes: 42 additions & 0 deletions config.au3
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Func toBoolean($var)
If IsBool($var) then
return $var
elseif IsNumber($var) then
return $var = 0 ? False : True
elseif IsString($var) then
local $str = StringLower($var)
if $str = "true" or $str = "1" or $str = "+" or $str = "y" or $str = "yes" then
return True
elseif $str = "false" or $str = "0" or $str = "-" or $str = "n" or $str = "no" then
return False
endif
else
MsgBox(16, @ScriptName, "toBoolean conversion error" & @CRLF _
& "Could not convert input to boolean." & @CRLF _
& "Value (as String):" & @CRLF _
& String($var) _
)
endif
endfunc

; this is executed before single-instance check, idc
Global Const $CFG_NAME = "wc3-code-paste-config.ini"

If FileExists($CFG_NAME) = 1 then
Global Const $CFG_SEND_KEY_DELAY = Number(IniRead($CFG_NAME, "general", "SendKeyDelay", 50))
Global Const $CFG_SEND_KEY_DOWN_DELAY = Number(IniRead($CFG_NAME, "general", "SendKeyDownDelay", 100))

Global Const $CFG_ENABLE_SOUND = toBoolean(IniRead($CFG_NAME, "sound", "enabled", True))

; inclusive 127 UTF-8 characters. Tested on v1.32.10
Global Const $WC3_CHAT_LENGTH_LIMIT = Number(IniRead($CFG_NAME, "warcraft", "chat_length_limit", 127))
else
IniWrite($CFG_NAME, "general", "SendKeyDelay", "50")
IniWrite($CFG_NAME, "general", "SendKeyDownDelay", "100")
IniWrite($CFG_NAME, "sound", "enabled", "true")
IniWrite($CFG_NAME, "warcraft", "chat_length_limit", "127")
Endif




18 changes: 11 additions & 7 deletions wc3-code-paste-helper.au3
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
#include <Process.au3>

#include "CreateSemaphore_udf.au3"
#include "config.au3"

; Attempted:
; See with API Monitor v2 whether game uses RegisterHotkey: NO
; Hook other Clipboard functions: None showed up
; Try PostMessage for unattended pasting: Nope
; Plain Send: works :/

Global Const $WC3_CHAT_LENGTH_LIMIT = 127 ; inclusive. Tested on v1.32.10


Func displayArray(ByRef $array)
Local $arrayLength = UBound($array)

Expand Down Expand Up @@ -146,8 +144,8 @@ Func copyPasteCodeToWc3()
if $wc3Lines[0] <> "" then
local $sendKeyDelay_restore = AutoItSetOption("SendKeyDelay")
local $sendKeyDownDelay_restore = AutoItSetOption("SendKeyDownDelay")
AutoItSetOption("SendKeyDelay", 50)
AutoItSetOption("SendKeyDownDelay", 100)
AutoItSetOption("SendKeyDelay", $CFG_SEND_KEY_DELAY)
AutoItSetOption("SendKeyDownDelay", $CFG_SEND_KEY_DOWN_DELAY)

Send("{ENTER}")
for $i = 1 to UBound($wc3Lines)-1
Expand All @@ -167,7 +165,7 @@ Func copyPasteCodeToWc3()
AutoItSetOption("SendKeyDelay", $sendKeyDelay_restore)
AutoItSetOption("SendKeyDownDelay", $sendKeyDownDelay_restore)
ClipPut($wc3Lines[0]) ; restore clipboard
Beep(800,200)
BeepOptional(800,200)
endif
Endfunc

Expand All @@ -188,6 +186,12 @@ Func enforceSingleInstance()
endif
Endfunc

Func BeepOptional($freqHz = 500, $durationMs = 1000)
if $CFG_ENABLE_SOUND then
Beep($freqHz, $durationMs)
endif
Endfunc

enforceSingleInstance()
Global $user32H = DllOpen("user32.dll")
While 1
Expand All @@ -202,7 +206,7 @@ While 1
; and remain in CTRL_DOWN state system-wide!
Wend

Beep(500,200)
BeepOptional(500,200)
copyPasteCodeToWc3()

Sleep(300)
Expand Down

0 comments on commit bc67504

Please sign in to comment.