From 1c103090b1b16ce5726cc9ec23a69d3f61a81104 Mon Sep 17 00:00:00 2001 From: Piotr Machacz Date: Thu, 29 Apr 2021 20:58:46 +0200 Subject: [PATCH] Fix to work with new window titles, make hotkeys also work in STS window --- buffers.au3 | 223 ++++++++++++++++----------------- rts.au3 | 348 ++++++++++++++++++++++++++-------------------------- 2 files changed, 287 insertions(+), 284 deletions(-) diff --git a/buffers.au3 b/buffers.au3 index f3cf251..593de17 100644 --- a/buffers.au3 +++ b/buffers.au3 @@ -1,111 +1,114 @@ -#include ;used to play default beep -Dim $Buffers[1];Each element will be a nested array containing all lines of a monitored window, this will be redimmed at initialisation -$WhichBuffer=0 -$BufferCursor=0 -$BufferKeysActive=0 -Func BufferNavigate() -If IsArray($Buffers[$WhichBuffer]) then -select -case @HotkeyPressed="!{up}" -If $BufferCursor>0 then -$BufferCursor=$BufferCursor-1 -If $bufferCursor>UBound(($Buffers[$WhichBuffer]))-1 then $BufferCursor=UBound(($Buffers[$WhichBuffer]))-1 -;Going up in a shrunken buffer while the cursor is out of bounds. -else -_WinAPI_MessageBeep(0) -EndIf -case @HotkeyPressed="!{down}" -If $BufferCursor0 then -$WhichBuffer=$WhichBuffer-1 -else ;First Buffer, so wrap around to the last -$WhichBuffer=UBound($WindowList)-1 -EndIf -EndSelect -;Now do Alt+Numbers -For $i=1 to 9 step 1 -If @HotkeyPressed="!"&$i then -If $i<=UBound($buffers) then -$WhichBuffer=$i-1 -else;No buffer with that number -_WinAPI_MessageBeep(0) -EndIf -EndIf -next -Speak($WindowList[$WhichBuffer]) -EndFunc -Func BufferCopy() -If ClipPut(($Buffers[$WhichBuffer])[$BufferCursor]) then -Speak("Copied " & (($Buffers[$WhichBuffer])[$BufferCursor])) -EndIf -EndFunc -Func RegisterBufferKeys($OnOrOff) -If $OnOrOff=1 then -HotkeySet("!{down}", "BufferNavigate") -HotkeySet("!{up}", "BufferNavigate") -HotkeySet("!{home}", "BufferNavigate") -HotkeySet("!{end}", "BufferNavigate") -HotKeySet("!{right}", "BufferSwitch") -HotKeySet("!{left}", "BufferSwitch") -For $i=1 to 9 step 1 -HotKeySet("!"&$i, "BufferSwitch") -next -HotKeySet("!c", "BufferCopy") -return -else -HotkeySet("!{down}") -HotkeySet("!{up}") -HotkeySet("!{home}") -HotkeySet("!{end}") -HotKeySet("!{right}") -HotKeySet("!{left}") -For $i=1 to 9 step 1 -HotKeySet("!"&$i) -next - -HotKeySet("!c") -EndIf -EndFunc - -func IsInGame() -For $i=0 to UBound($WindowList)-1 step 1 -If WinGetHandle("[ACTIVE]")=$HandleList[$i][0] then -Return true -ExitLoop -EndIf -next -If WinActive("Prompt") then -return true -else -return false -EndIf +#include ;used to play default beep +Dim $Buffers[1];Each element will be a nested array containing all lines of a monitored window, this will be redimmed at initialisation +$WhichBuffer=0 +$BufferCursor=0 +$BufferKeysActive=0 +Func BufferNavigate() +If IsArray($Buffers[$WhichBuffer]) then +select +case @HotkeyPressed="!{up}" +If $BufferCursor>0 then +$BufferCursor=$BufferCursor-1 +If $bufferCursor>UBound(($Buffers[$WhichBuffer]))-1 then $BufferCursor=UBound(($Buffers[$WhichBuffer]))-1 +;Going up in a shrunken buffer while the cursor is out of bounds. +else +_WinAPI_MessageBeep(0) +EndIf +case @HotkeyPressed="!{down}" +If $BufferCursor0 then +$WhichBuffer=$WhichBuffer-1 +else ;First Buffer, so wrap around to the last +$WhichBuffer=UBound($WindowList)-1 +EndIf +EndSelect +;Now do Alt+Numbers +For $i=1 to 9 step 1 +If @HotkeyPressed="!"&$i then +If $i<=UBound($buffers) then +$WhichBuffer=$i-1 +else;No buffer with that number +_WinAPI_MessageBeep(0) +EndIf +EndIf +next +Speak($WindowList[$WhichBuffer]) +EndFunc +Func BufferCopy() +If ClipPut(($Buffers[$WhichBuffer])[$BufferCursor]) then +Speak("Copied " & (($Buffers[$WhichBuffer])[$BufferCursor])) +EndIf +EndFunc +Func RegisterBufferKeys($OnOrOff) +If $OnOrOff=1 then +HotkeySet("!{down}", "BufferNavigate") +HotkeySet("!{up}", "BufferNavigate") +HotkeySet("!{home}", "BufferNavigate") +HotkeySet("!{end}", "BufferNavigate") +HotKeySet("!{right}", "BufferSwitch") +HotKeySet("!{left}", "BufferSwitch") +For $i=1 to 9 step 1 +HotKeySet("!"&$i, "BufferSwitch") +next +HotKeySet("!c", "BufferCopy") +return +else +HotkeySet("!{down}") +HotkeySet("!{up}") +HotkeySet("!{home}") +HotkeySet("!{end}") +HotKeySet("!{right}") +HotKeySet("!{left}") +For $i=1 to 9 step 1 +HotKeySet("!"&$i) +next + +HotKeySet("!c") +EndIf +EndFunc + +func IsInGame() +For $i=0 to UBound($WindowList)-1 step 1 +If WinGetHandle("[ACTIVE]")=$HandleList[$i][0] then +Return true +ExitLoop +EndIf +next +If WinGetHandle("[ACTIVE]")=$STSHandle then + return true + EndIf +If WinActive("Prompt") then +return true +else +return false +EndIf EndFunc \ No newline at end of file diff --git a/rts.au3 b/rts.au3 index 03139ee..dab42a2 100644 --- a/rts.au3 +++ b/rts.au3 @@ -1,175 +1,175 @@ -#pragma compile(CompanyName, 'Piotr Machacz') -#pragma compile (FileDescription, ReadTheSpire) -#pragma compile(ProductName, ReadTheSpire) -#Pragma compile (ProductVersion, 3.22) - -#include "tolk.au3" -#include "buffers.au3" -#include -#include -AutoItSetOption("WinTextMatchMode", -1) -_Singleton("ReadTheSpire");exit if there's more than 1 copy running -$WindowList=FileReadToArray("watchlist.txt") -Dim $HandleList[UBound($WindowList)][2] -If @error then -Msgbox(16, "Error", "Couldn't read Watchlist. The file may either be empty, inaccessible or not exist.") -exit -EndIf -dim $SilentWindowList[UBound($WindowList)] -For $i=0 to UBound($WindowList)-1 step 1 -If StringLeft($WindowList[$i], 1)="*" then;Silent window -$SilentWindowList[$i]=true -$WindowList[$i]=StringTrimLeft($WindowList[$i], 1) -EndIf -next -$SubstitutionList=FileReadToArray("substitutions.txt") - -If @error then -Msgbox(16, "Error", "Couldn't read substitutions. The file may either be empty, inaccessible or not exist.") -exit -EndIf -Dim $Substitutions[UBound($SubstitutionList)][2] - -For $i=0 to UBound($SubstitutionList)-1 step 1 -$TempArray=StringSplit($SubstitutionList[$i], "=", 2) -If not @error then -$Substitutions[$i][0]=$TempArray[0] -$Substitutions[$i][1]=$TempArray[1] -EndIf -Next - -dim $OldText[UBound($WindowList)] -Dim $buffers[UBound($WindowList)] -Tolk_Load() -if not Tolk_IsLoaded() then -Msgbox(16, "Error", "Tolk failed to load!") -exit -EndIf -Tolk_TrySapi(true) -func speak($text) -If Not StringIsSpace($text) then tolk_output($text);Suppress blank lines because NVDA gets chatty -;_ArrayDisplay(StringToASCIIArray($text)) -endFunc -func Quit() -Speak("Exitting") -exit -EndFunc -HotKeySet("^q", "Quit") -If WinExists("Slay the Spire")=0 then;Launch the MTS launcher -$MTSDir=FileRead("MTSDir.txt") -If $MTSDir="" then ;Look for the file in the most common directories -$Dirs=StringSplit("C:\Program Files (x86)\Steam\steamapps\common\SlayTheSpire\|D:\Program Files (x86)\Steam\steamapps\common\SlayTheSpire\", "|", 2) -For $i=0 to UBound($dirs)-1 step 1 -;Msgbox(0, "checking", $Dirs[$i]) -If FileExists($dirs[$i] & "mts-launcher.jar") then -$MTSDir=$Dirs[$i] -;msgBox(64, "Success", $Dirs[$i]) -ExitLoop -EndIf -Next -If $MTSDir="" then $MTSDir=FileSelectFolder("Browse to Slay the Spire installation folder", "") -If @error then -$NoLaunch=Msgbox(32+4, "Question", "Would you like to make ReadTheSpire not start MTS-launcher at startup?") -If $NoLaunch=6 then ;yes -$MTSDir="none" -MsgBox(64, "Done", "If you later want to specify the location of MTS-launcher, delete MTSDir.txt located in the ReadTheSpire folder.") -else ;no -exit -EndIf -EndIf;Looks for MTS-launcher.jar -FileWrite("MTSDir.txt", $MTSDir) -EndIf - -If $MTSDir <>"none" then -FileChangeDir($MTSDir) -If FileExists("modthespire.jar") then -ShellExecute("modthespire.jar");For Gog version -else -ShellExecute("mts-launcher.jar") -EndIf -If @error then - msgbox(16, "Error", "MTSLauncher was found but didn't start correctly. Please make sure you have Java installed and that it's set to open .jar files.") - Exit -EndIf - -speak("MTS Launcher started, waiting for game to start") -else -speak("ReadTheSpire ready, waiting for you to start the game.") -EndIf - -do -sleep(250) -until WinExists("Slay the Spire") -EndIf;Look if the game is open, otherwise launch it. -$STSHandle=WinGetHandle("Slay the Spire") -while WinExists($STSHandle)=1 -If $BufferKeysActive=0 and IsInGame() then -$BufferKeysActive=1 -RegisterBufferKeys(1) -ElseIf not IsInGame() and $BufferKeysActive=1 then -$BufferKeysActive=0 -RegisterBufferKeys(0) -EndIf - -for $i=0 to UBound($WindowList)-1 step 1 -If $HandleList[$i][0]=0 then -$HandleList[$i][0]=WinGetHandle($WindowList[$i]) -;If not @error then speak($WindowList[$i] & " opened.") -EndIf -If $HandleList[$i][0] <>0 then -If $HandleList[$i][1]=0 then $HandleList[$i][1]=ControlGetHandle($HandleList[$i][0], "", "[CLASS:Edit]") - $text=ControlGetText($HandleList[$i][0], "", $HandleList[$i][1]) -If @error then -;speak($WindowList[$i] & " closed.") -$HandleList[$i][0]=0 -$HandleList[$i][1]=0 -else -If $text <> $OldText[$i] then; speak the new text! -$buffers[$i]=StringSplit($text, @crlf, 3);update the buffers -If $SilentWindowList[$i]=false then -$TextToSpeak=$Text;The RegExp substitutions will happen on this variable instead of the original text as to not break the comparisons. -For $i3=0 to UBound($Substitutions)-1 step 1 -$TextToSpeak=StringRegExpReplace($TextToSpeak, $Substitutions[$i3][0], $Substitutions[$i3][1]) -If @error then -MsgBox(16, "Regexp Error", "error in expression " & $Substitutions[$i3]) -exit -EndIf -;If @extended>0 then MsgBox(0, "matched", "replaced " & $Substitutions[$i3][0] & " with " & $Substitutions[$i3][1] & " text is now " & $TextToSpeak) -next -$SpokeWindowName=0 - -If $WindowList[$i]="Output" then ;The entire output Window should always be reread since that's generally requested by the player -Speak($textToSpeak) - -else ;For other windows, compare the old and newly changed text line by line to only anounce the ones that changed. -$OldArray=StringSplit($OldText[$i], @crlf, 1) -$NewArray=StringSplit($TextToSpeak, @crlf, 1) -For $i2=1 to $NewArray[0] step 1 -If $i2$NewArray[$i2] then -If $SpokeWindowName=0 then -$NewArray[$i2]=$WindowList[$i] & ": " & $NewArray[$i2] -$SpokeWindowName=1 -EndIf -Speak($NewArray[$i2]);Only speak the line if it changed -endIf ;If $OldArray[$i2]<>$NewArray[$i2] -else;The new text has more lines than the old, so just speak all of them -If $SpokeWindowName=0 then -$NewArray[$i2]=$WindowList[$i] & ": " & $NewArray[$i2] -$SpokeWindowName=1 -EndIf - -Speak($NewArray[$i2]) -EndIf -next -EndIf;Output or other windows check -EndIf;Speak if the text was different -EndIf ;Silent window or not checks -$OldText[$i]=$text;Set the old text to the new -EndIf -EndIf - -next - -sleep(30) +#pragma compile(CompanyName, 'Piotr Machacz') +#pragma compile (FileDescription, ReadTheSpire) +#pragma compile(ProductName, ReadTheSpire) +#Pragma compile (ProductVersion, 3.22) + +#include "tolk.au3" +#include "buffers.au3" +#include +#include +AutoItSetOption("WinTextMatchMode", -1) +_Singleton("ReadTheSpire");exit if there's more than 1 copy running +$WindowList=FileReadToArray("watchlist.txt") +Dim $HandleList[UBound($WindowList)][2] +If @error then +Msgbox(16, "Error", "Couldn't read Watchlist. The file may either be empty, inaccessible or not exist.") +exit +EndIf +dim $SilentWindowList[UBound($WindowList)] +For $i=0 to UBound($WindowList)-1 step 1 +If StringLeft($WindowList[$i], 1)="*" then;Silent window +$SilentWindowList[$i]=true +$WindowList[$i]=StringTrimLeft($WindowList[$i], 1) +EndIf +next +$SubstitutionList=FileReadToArray("substitutions.txt") + +If @error then +Msgbox(16, "Error", "Couldn't read substitutions. The file may either be empty, inaccessible or not exist.") +exit +EndIf +Dim $Substitutions[UBound($SubstitutionList)][2] + +For $i=0 to UBound($SubstitutionList)-1 step 1 +$TempArray=StringSplit($SubstitutionList[$i], "=", 2) +If not @error then +$Substitutions[$i][0]=$TempArray[0] +$Substitutions[$i][1]=$TempArray[1] +EndIf +Next + +dim $OldText[UBound($WindowList)] +Dim $buffers[UBound($WindowList)] +Tolk_Load() +if not Tolk_IsLoaded() then +Msgbox(16, "Error", "Tolk failed to load!") +exit +EndIf +Tolk_TrySapi(true) +func speak($text) +If Not StringIsSpace($text) then tolk_output($text);Suppress blank lines because NVDA gets chatty +;_ArrayDisplay(StringToASCIIArray($text)) +endFunc +func Quit() +Speak("Exitting") +exit +EndFunc +HotKeySet("^q", "Quit") +If WinExists("Modded Slay the Spire")=0 then;Launch the MTS launcher +$MTSDir=FileRead("MTSDir.txt") +If $MTSDir="" then ;Look for the file in the most common directories +$Dirs=StringSplit("C:\Program Files (x86)\Steam\steamapps\common\SlayTheSpire\|D:\Program Files (x86)\Steam\steamapps\common\SlayTheSpire\", "|", 2) +For $i=0 to UBound($dirs)-1 step 1 +;Msgbox(0, "checking", $Dirs[$i]) +If FileExists($dirs[$i] & "mts-launcher.jar") then +$MTSDir=$Dirs[$i] +;msgBox(64, "Success", $Dirs[$i]) +ExitLoop +EndIf +Next +If $MTSDir="" then $MTSDir=FileSelectFolder("Browse to Slay the Spire installation folder", "") +If @error then +$NoLaunch=Msgbox(32+4, "Question", "Would you like to make ReadTheSpire not start MTS-launcher at startup?") +If $NoLaunch=6 then ;yes +$MTSDir="none" +MsgBox(64, "Done", "If you later want to specify the location of MTS-launcher, delete MTSDir.txt located in the ReadTheSpire folder.") +else ;no +exit +EndIf +EndIf;Looks for MTS-launcher.jar +FileWrite("MTSDir.txt", $MTSDir) +EndIf + +If $MTSDir <>"none" then +FileChangeDir($MTSDir) +If FileExists("modthespire.jar") then +ShellExecute("modthespire.jar");For Gog version +else +ShellExecute("mts-launcher.jar") +EndIf +If @error then + msgbox(16, "Error", "MTSLauncher was found but didn't start correctly. Please make sure you have Java installed and that it's set to open .jar files.") + Exit +EndIf + +speak("MTS Launcher started, waiting for game to start") +else +speak("ReadTheSpire ready, waiting for you to start the game.") +EndIf + +do +sleep(250) +until WinExists("Modded Slay the Spire") +EndIf;Look if the game is open, otherwise launch it. +$STSHandle=WinGetHandle("Modded Slay the Spire") +while WinExists($STSHandle)=1 +If $BufferKeysActive=0 and IsInGame() then +$BufferKeysActive=1 +RegisterBufferKeys(1) +ElseIf not IsInGame() and $BufferKeysActive=1 then +$BufferKeysActive=0 +RegisterBufferKeys(0) +EndIf + +for $i=0 to UBound($WindowList)-1 step 1 +If $HandleList[$i][0]=0 then +$HandleList[$i][0]=WinGetHandle($WindowList[$i]) +;If not @error then speak($WindowList[$i] & " opened.") +EndIf +If $HandleList[$i][0] <>0 then +If $HandleList[$i][1]=0 then $HandleList[$i][1]=ControlGetHandle($HandleList[$i][0], "", "[CLASS:Edit]") + $text=ControlGetText($HandleList[$i][0], "", $HandleList[$i][1]) +If @error then +;speak($WindowList[$i] & " closed.") +$HandleList[$i][0]=0 +$HandleList[$i][1]=0 +else +If $text <> $OldText[$i] then; speak the new text! +$buffers[$i]=StringSplit($text, @crlf, 3);update the buffers +If $SilentWindowList[$i]=false then +$TextToSpeak=$Text;The RegExp substitutions will happen on this variable instead of the original text as to not break the comparisons. +For $i3=0 to UBound($Substitutions)-1 step 1 +$TextToSpeak=StringRegExpReplace($TextToSpeak, $Substitutions[$i3][0], $Substitutions[$i3][1]) +If @error then +MsgBox(16, "Regexp Error", "error in expression " & $Substitutions[$i3]) +exit +EndIf +;If @extended>0 then MsgBox(0, "matched", "replaced " & $Substitutions[$i3][0] & " with " & $Substitutions[$i3][1] & " text is now " & $TextToSpeak) +next +$SpokeWindowName=0 + +If $WindowList[$i]="Output" then ;The entire output Window should always be reread since that's generally requested by the player +Speak($textToSpeak) + +else ;For other windows, compare the old and newly changed text line by line to only anounce the ones that changed. +$OldArray=StringSplit($OldText[$i], @crlf, 1) +$NewArray=StringSplit($TextToSpeak, @crlf, 1) +For $i2=1 to $NewArray[0] step 1 +If $i2$NewArray[$i2] then +If $SpokeWindowName=0 then +$NewArray[$i2]=$WindowList[$i] & ": " & $NewArray[$i2] +$SpokeWindowName=1 +EndIf +Speak($NewArray[$i2]);Only speak the line if it changed +endIf ;If $OldArray[$i2]<>$NewArray[$i2] +else;The new text has more lines than the old, so just speak all of them +If $SpokeWindowName=0 then +$NewArray[$i2]=$WindowList[$i] & ": " & $NewArray[$i2] +$SpokeWindowName=1 +EndIf + +Speak($NewArray[$i2]) +EndIf +next +EndIf;Output or other windows check +EndIf;Speak if the text was different +EndIf ;Silent window or not checks +$OldText[$i]=$text;Set the old text to the new +EndIf +EndIf + +next + +sleep(30) Wend \ No newline at end of file