From bc6750467c3071e6ca949f2ea1a75cb8985c382b Mon Sep 17 00:00:00 2001 From: Luashine <103937213+Luashine@users.noreply.github.com> Date: Mon, 14 Nov 2022 22:48:27 +0100 Subject: [PATCH] Add config options --- .gitignore | 1 + README.md | 1 + config.au3 | 42 +++++++++++++++++++++++++++++++++++++++ wc3-code-paste-helper.au3 | 18 ++++++++++------- 4 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 .gitignore create mode 100644 config.au3 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d2127d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.ini diff --git a/README.md b/README.md index 464b666..73d6f06 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/config.au3 b/config.au3 new file mode 100644 index 0000000..912bbcf --- /dev/null +++ b/config.au3 @@ -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 + + + + diff --git a/wc3-code-paste-helper.au3 b/wc3-code-paste-helper.au3 index 55b10d3..be17217 100644 --- a/wc3-code-paste-helper.au3 +++ b/wc3-code-paste-helper.au3 @@ -5,6 +5,7 @@ #include #include "CreateSemaphore_udf.au3" +#include "config.au3" ; Attempted: ; See with API Monitor v2 whether game uses RegisterHotkey: NO @@ -12,9 +13,6 @@ ; 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) @@ -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 @@ -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 @@ -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 @@ -202,7 +206,7 @@ While 1 ; and remain in CTRL_DOWN state system-wide! Wend - Beep(500,200) + BeepOptional(500,200) copyPasteCodeToWc3() Sleep(300)