Skip to content

Commit

Permalink
0.8.0-pre2
Browse files Browse the repository at this point in the history
* Fixed mulligan grammar
* Rewrote active window detection, added bypass option in config
  • Loading branch information
topher-au committed Aug 30, 2015
1 parent 3cd78be commit 765d79c
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 27 deletions.
7 changes: 5 additions & 2 deletions HDT-Voice/HDTPlugin/HDTVoicePlugin.vb
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ Public Class HDTVoicePlugin
End Sub
Public Sub OnUnload() Implements IPlugin.OnUnload
My.Settings.Save()
voicePlugin.Unload()
voicePlugin = Nothing
If Not voicePlugin Is Nothing Then
voicePlugin.Unload()
voicePlugin = Nothing
End If

For Each t In FindVisualChildren(Of TreeView)(Helper.OptionsMain)
For Each ti As TreeViewItem In FindVisualChildren(Of TreeViewItem)(t)
If ti.Header = "Voice Control" Then
Expand Down
3 changes: 3 additions & 0 deletions HDT-Voice/HDTPlugin/configMain.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<DockPanel Margin="10">
<CheckBox Name="checkDebugLog" Content="Enable debug logfile" />
</DockPanel>
<DockPanel Margin="10">
<CheckBox Name="checkHearthstoneActive" Content="Don't send commands unless Hearthstone is active" />
</DockPanel>
<DockPanel Margin="20">
<Button Name="buttonUpdate" Content="Check for Updates" Height="48"/>
</DockPanel>
Expand Down
4 changes: 4 additions & 0 deletions HDT-Voice/HDTPlugin/configMain.xaml.vb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Public Class configMain
checkDebugLog.IsChecked = My.Settings.boolDebugLog
AddHandler checkDebugLog.Click, AddressOf SaveSettings

checkHearthstoneActive.IsChecked = My.Settings.boolHearthActive
AddHandler checkHearthstoneActive.Click, AddressOf SaveSettings

AddHandler buttonUpdate.Click, AddressOf ClickUpdateButton


Expand All @@ -35,6 +38,7 @@ Public Class configMain
My.Settings.intNotificationSize = comboNotificationSize.SelectedIndex
My.Settings.boolSmoothCursor = checkSmoothMouse.IsChecked
My.Settings.boolDebugLog = checkDebugLog.IsChecked
My.Settings.boolHearthActive = checkHearthstoneActive.IsChecked
My.Settings.Save()

comboNotificationSize.IsEnabled = checkShowNotification.IsChecked
Expand Down
16 changes: 8 additions & 8 deletions HDT-Voice/HDTVoice/HDTGrammarEngine.vb
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ Public Class HDTGrammarEngine
Dim cardsInHand = GetCardsInHand()
Dim mulliganChoices As New Choices

Dim mulliBuilder As New GrammarBuilder
If Not My.Settings.boolQuickPlay Then _
mulliBuilder.Append(ResChoice("MULLIGANCLICK"))

If cardsInHand.Count > 0 Then
Dim myHand = FriendlyHandChoices()
Dim mulliganCard As New GrammarBuilder
If Not My.Settings.boolQuickPlay Then _
mulliganCard.Append(ResChoice("MULLIGANCLICK"))
mulliganCard.Append(New SemanticResultKey("card", FriendlyHandChoices))
mulliganChoices.Add(New SemanticResultKey("mulligan", mulliganCard))
mulliganChoices.Add(New SemanticResultKey("mulligan", myHand))
End If
mulliganChoices.Add(ResChoice("MULLIGANCONFIRM"))
mulliBuilder.Append(New SemanticResultKey("mulligan", mulliganChoices))

mulliganChoices.Add(New SemanticResultKey("mulligan", ResChoice("MULLIGANCONFIRM")))

Dim returnGrammar As New Grammar(mulliganChoices)
Dim returnGrammar As New Grammar(mulliBuilder)
returnGrammar.Name = Reflection.MethodBase.GetCurrentMethod.Name.ToString
Return returnGrammar
End Function
Expand Down
60 changes: 43 additions & 17 deletions HDT-Voice/HDTVoice/HDTVoice.vb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Public Class HDTVoice
Private Declare Function GetForegroundWindow Lib "user32" () As System.IntPtr
Private Declare Auto Function GetWindowText Lib "user32" (ByVal hWnd As System.IntPtr, ByVal lpString As System.Text.StringBuilder, ByVal cch As Integer) As Integer
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Integer) As Short
Public Declare Auto Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As IntPtr, ByRef lpdwProcessId As IntPtr) As IntPtr
Public Declare Function OpenProcess Lib "kernel32" (dwDesiredAccess As Integer, bInheritHandle As Boolean, dwProcessId As Integer) As Long
Public Declare Function GetProcessImageFileName Lib "psapi.dll" Alias "GetProcessImageFileNameA" (hProcess As Integer, lpImageFileName As String, nSize As Integer) As Integer
Public Declare Function CloseHandle Lib "kernel32" (hObject As Integer) As Integer

' Speech recognition objects
Private WithEvents recogVoice As SpeechRecognitionEngine
Expand Down Expand Up @@ -134,15 +138,17 @@ Public Class HDTVoice
workerHotkey.RunWorkerAsync() ' Start listening for hotkey
workerActions.RunWorkerAsync() ' Start action processor

If My.Settings.boolToggleOrPtt Then ' Push to talk enabled, don't start listening
sreListen = False
PopupNotification("HDT-Voice loaded (hold Left Shift to speak)", 4000)
ElseIf My.Settings.boolListenAtStartup Then ' Start listening
sreListen = True
PopupNotification("HDT-Voice loaded and enabled (F12 to disable)", 4000)
Else 'Don't start listening
sreListen = False
PopupNotification("HDT-Voice loaded (F12 to enable)", 4000)
If canvasOverlay.ActualWidth > 500 Then
If My.Settings.boolToggleOrPtt Then ' Push to talk enabled, don't start listening
sreListen = False
PopupNotification("Speech recognition enabled (push-to-talk)", 4000)
ElseIf My.Settings.boolListenAtStartup Then ' Start listening
sreListen = True
PopupNotification("Speech recognition enabled (F12 to toggle)", 4000)
Else 'Don't start listening
sreListen = False
PopupNotification("Speech recognition disabled (F12 to toggle)", 4000)
End If
End If
End Sub ' Run when the plugin is first initialized
Public Sub Unload()
Expand Down Expand Up @@ -402,13 +408,11 @@ Public Class HDTVoice

Select Case e.Result.Semantics.First.Key
Case "mulligan"
Dim mulliganTarget As String = e.Result.Semantics("mulligan").Item("card").Value

If mulliganTarget = My.Resources.MULLIGANCONFIRM Then ' Confirm selection
If My.Resources.MULLIGANCONFIRM.Contains(e.Result.Text) Then
Mouse.MoveTo(50, 80)
Mouse.SendClick(Mouse.Buttons.Left)
Else ' Card to mulligan specified
Dim cardEntity = GrammarEngine.GetEntityFromSemantic(mulliganTarget)
Else
Dim cardEntity = GrammarEngine.GetEntityFromSemantic(e.Result.Semantics("mulligan").Value)
Dim targetNum = cardEntity.GetTag(GAME_TAG.ZONE_POSITION)
Mouse.MoveToMulligan(targetNum)
Mouse.SendClick(Mouse.Buttons.Left)
Expand Down Expand Up @@ -734,15 +738,37 @@ Public Class HDTVoice

'Miscellaneous functions
Public Function IsHearthstoneActive() As Boolean
If Not My.Settings.boolHearthActive Then Return True
Dim activeHwnd = GetForegroundWindow()
Dim activeWindowText As New System.Text.StringBuilder(32)
GetWindowText(activeHwnd, activeWindowText, activeWindowText.Capacity)
If activeWindowText.ToString = "Hearthstone" Then
Dim winProcess As IntPtr
GetWindowThreadProcessId(activeHwnd, winProcess)
Dim ProcessFilename As String = GetProcessFilename(winProcess)
If ProcessFilename = "Hearthstone.exe" Then
Return True
Else
Return False
End If
End Function 'Checks if the hearthstone window is active
Private Function GetProcessFilename(ProcessID As Long) As String
GetProcessFilename = Nothing
Const MAX_PATH = 260
Const PROCESS_QUERY_INFORMATION = &H400
Const PROCESS_VM_READ = &H10

Dim strBuffer As String
Dim bufferLength As Integer, processHandle As Integer
strBuffer = New String(Chr(0), MAX_PATH)
processHandle = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0, ProcessID)
If processHandle Then
bufferLength = GetProcessImageFileName(processHandle, strBuffer, MAX_PATH)
If bufferLength Then
strBuffer = Left$(strBuffer, bufferLength)
GetProcessFilename = strBuffer.Substring(strBuffer.LastIndexOf("\") + 1)
End If
CloseHandle(processHandle)
End If
Return GetProcessFilename
End Function
Public Sub writeLog(LogLine As String, ParamArray args As Object())
Dim formatLine As String = String.Format(LogLine, args)
formatLine = String.Format("HDT-Voice: {0}", formatLine)
Expand Down
12 changes: 12 additions & 0 deletions HDT-Voice/My Project/Settings.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions HDT-Voice/My Project/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@
<Setting Name="intNotificationSize" Type="System.Int32" Scope="User">
<Value Profile="(Default)">1</Value>
</Setting>
<Setting Name="boolHearthActive" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
3 changes: 3 additions & 0 deletions HDT-Voice/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
<setting name="intNotificationSize" serializeAs="String">
<value>1</value>
</setting>
<setting name="boolHearthActive" serializeAs="String">
<value>True</value>
</setting>
</HDTVoice.My.MySettings>
</userSettings>
</configuration>

0 comments on commit 765d79c

Please sign in to comment.