-
Notifications
You must be signed in to change notification settings - Fork 0
/
WoWNotifier.ps1
714 lines (597 loc) · 27.8 KB
/
WoWNotifier.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
#########################################################################
# Name: WoWNotifier #
# Desc: Notifies you when your World of Warcraft Queue has ended #
# Author: Ninthwalker #
# Instructions: https://github.com/ninthwalker/WoWNotifier #
# Date: 30SEP2022 #
# Version: 1.0 #
#########################################################################
############################## CHANGE LOG ###############################
## 1.0 #
# Initial App version (Modified from my original BGNotifier) #
#########################################################################
using namespace Windows.Storage
using namespace Windows.Graphics.Imaging
##########################################
### CHANGE THESE SETTINGS TO YOUR OWN! ###
##########################################
### REQUIRED SETTINGS ###
#########################
# One or more notification apps are required. One or All of them can be used at the same time.
# Set the notification app you want to use to '$True' to enable it or '$False' to disable it.
# Then enter your webhook or API type tokens for the notification type you want to use.
# All Notifications are set to $False by default.
# See the Advanced section below this for extra features.
## DISCORD ##
$discord = $False
# Your Discord Channel Webhook. Put your own here.
$discordWebHook = "https://discordapp.com/api/webhooks/4593 - EXAMPLE - EVn24sRzpn5KspJHRebCkldhsklrh2378rUIPG8DWgUEtQpEunzGn7ysJ-rT"
## TELEGRAM ##
$telegram = $False
# Get the Token by creating a bot by messaging @BotFather
$telegramBotToken = "96479117:BAH0 - EXAMPLE - yzTvrc6wUKLHKGYUyu34hm2zOgbQDBMu4"
# Get the ChatID by messaging your bot you created, or making your own group with the bot and messaging the group. Then get the ChatID for that conversation with the below step.
# Then go to this url replacing <telegramBotToken> with your own Bots token and look for the chatID to use. https://api.telegram.org/bot<telegramBotToken>/getUpdates
$telegramChatID = "-371-EXAMPLE-556032"
## PUSHOVER ##
$pushover = $False
$pushoverAppToken = "GetFromPushoverDotNet"
$pushoverUserToken = "GetFromPushoverDotNet"
# optional Pushover settings. Uncomment and set if wanted.
#$device = "Device"
#$title = "Title"
#$priority = "Priority"
#$sound = "Sound"
## TEXT MESSAGE ##
$textMsg = $False
# Note: I didn't want to code in all the carriers and all the emails. So only gmail is fully supported for now. If using 2FA, make a google app password from here: https://myaccount.google.com/security
# Feel free to do a pull request to add more if it doesn't work with these default settings optinos. Or just edit the below code with your own carrier and email settings.
# Enter carrier email, should be in the format of: "@vtext.com", "@txt.att.net", "@messaging.sprintpcs.com", "@tmomail.net", "@msg.fi.google.com"
$CarrierEmail = "@txt.att.net" # change to your cell carrier
$phoneNumber = "your phone number" # I didn't need to enter a '1' in front of my number, but you may need to for some carriers
$smtpServer = "smtp.gmail.com" # change to your smtp if you dont use gmail. only Gmail tested though
$smtpPort = "587" # change to your email providers port if not gmail.
$fromAddress = "[email protected]" # usually your email
$emailUser = "[email protected]" # your email address
$emailPass = "your email pass or app password"
## ALEXA NOTIFY ME SKILL ##
$alexa = $False
# Enter in the super long access code that the skill emailed you when you set it up in Alexa"
$alexaAccessCode = "amzn1.ask.account.AEHQ4KJGYGIZ3ZZ - EXAMPLE - LMCMBLAHGKJHLIUHPIUHHTDOUDU567L72OXKPXXLVI568EJJVIHYO2DXGMPXPWZDLJKH678UFUYFJUHLIUG45684679GN2QQ7X23MGMHGGIAJSYG4U2SJIWUF3R5FUPDNPA5I"
## HOME ASSISTANT ##
# This is probably way more advanced than most people will use, but it's here for those that want it.
# I personally use this so my alexa devices will announce that the queue has ended.
$HASS = $False
# Your Home Assistant base url and port. ie:
$hassURL = "http://192.168.1.20:8123"
# token from Home Assistant
$hassToken = "eyJ0eXAiO - EXAMPLE - iMGDJKOPHRDCMLHHJK8GHGHtyutdiZ.nC15fj0dBr7MRPqee2Dj_eQSS5rLPfdYhjhgljhg34df32f2fgerKHJVmhOi9U"
# entity_id of the script you want to have execute (ie: script.2469282367234)
$entity_ID = "script.15372345285"
### OPTIONAL ADVANCED SETTINGS ###
##################################
# Coordinates of queue window. Change these to your own if you want to customize the area of the screenshot.
# Default settings are to screenshot the middle of your WoW window which should be good for most people, but not all.
# See Instructions on the Github page or use the 'Get Coords' within the app to find the area you want to scan for the Queue window.
# Change '$useMyOwnCoordinates' to "Yes" and set the coordinates to use your own.
$useMyOwnCoordinates = "No"
$topleftX = 1461
$topLeftY = 241
$bottomRightX = 1979
$bottomRightY = 356
# Screenshot Location to save temporary img to for OCR Scan. Change if you want it somewhere else.
$path = $env:temp
# Amount of seconds to wait before scanning the Queue window.
# Note: this script uses hardly any resources and is very quick at the screenshot/OCR process.
$delay = 30
# Option to stop WoWNotifier once the Queue has ended. "Yes" to stop the program, or "No" to keep it running.
# Default is 'Yes', stop scanning after it no longer detects the Queue window.
$stopOnQueue = "Yes"
# Set to "Yes" to enable alerts for what position in queue you are. Also set an interval time for how often it will notify you
# interval time in minutes. Optional, default is "No"
$queueCheck = "No"
$queueCheckInterval = 10
#########################################
### DO NOT MODIFY ANYTHING BELOW THIS ###
#########################################
# Force tls1.2 - mainly for telegram since they recently changed this in FEB2020
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# If usuing text method, convert password into secure credential object
if ($textMsg) {
[SecureString]$secureEmailPass = $emailPass | ConvertTo-SecureString -AsPlainText -Force
[PSCredential]$emailCreds = New-Object System.Management.Automation.PSCredential -ArgumentList $emailUser, $secureEmailPass
}
# Screenshot method
Add-Type -AssemblyName System.Windows.Forms,System.Drawing
# Add the WinRT assembly, and load the appropriate WinRT types
Add-Type -AssemblyName System.Runtime.WindowsRuntime
$null = [Windows.Storage.StorageFile, Windows.Storage, ContentType = WindowsRuntime]
$null = [Windows.Media.Ocr.OcrEngine, Windows.Foundation, ContentType = WindowsRuntime]
$null = [Windows.Foundation.IAsyncOperation`1, Windows.Foundation, ContentType = WindowsRuntime]
$null = [Windows.Graphics.Imaging.SoftwareBitmap, Windows.Foundation, ContentType = WindowsRuntime]
$null = [Windows.Storage.Streams.RandomAccessStream, Windows.Storage.Streams, ContentType = WindowsRuntime]
# used to find the queue window location coordinates on your monitor
function Get-Coords {
$form.TopMost = $True
$script:label_coords_text.Enabled = $False
$script:label_coords_text.Visible = $False
$button_start.Visible = $False
$label_status.Text = ""
$label_status.Refresh()
$script:label_coords1.Text = ""
$script:label_coords1.Refresh()
$script:label_coords2.Text = ""
$script:label_coords2.Refresh()
$script:label_coords1.Visible = $True
$script:label_coords2.Visible = $True
$script:label_coords_text2.Visible = $True
$script:label_coords_text2.Enabled = $True
$script:cancelLoop = $False
$count = 1
:coord While( $true ) {
If( (([System.Windows.Input.Keyboard]::IsKeyDown([System.Windows.Input.Key]::LeftShift)) -and ([System.Windows.Input.Keyboard]::IsKeyDown([System.Windows.Input.Key]::LeftCtrl))) -or ($script:cancelLoop) -or ($count -ge 3)) {
Break
}
If( [System.Windows.Forms.UserControl]::MouseButtons -ne "None" ) {
While( [System.Windows.Forms.UserControl]::MouseButtons -ne "None" ) {
Start-Sleep -Milliseconds 100 # Wait for the MOUSE UP event
[System.Windows.Forms.Application]::DoEvents()
}
$mp = [Windows.Forms.Cursor]::Position
if ($count -eq 1) {
$script:label_coords1.Text = "Top left: $($mp.ToString().Replace('{','').Replace('}',''))"
$script:label_coords1.Refresh()
$count++
}
elseif ($count -eq 2) {
$script:label_coords2.Text = "Bottom Right: $($mp.ToString().Replace('{','').Replace('}',''))"
$script:label_coords2.Refresh()
$count++
}
if ($count -ge 3) {
Break coord
}
}
[System.Windows.Forms.Application]::DoEvents()
Start-Sleep -Milliseconds 100
}
#[System.Windows.Forms.Application]::DoEvents()
if (($script:cancelLoop) -or ($count -ge 3)) {
Return
}
}
# Screenshot function
function Get-WoWQueue {
$bounds = [Drawing.Rectangle]::FromLTRB($topleftX, $topLeftY, $bottomRightX, $bottomRightY)
$pic = New-Object System.Drawing.Bitmap ([int]$bounds.width), ([int]$bounds.height)
$graphics = [Drawing.Graphics]::FromImage($pic)
$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)
$pic.Save("$path\WoWNotifier_Img.png")
$graphics.Dispose()
$pic.Dispose()
}
# OCR Scan Function
function Get-Ocr {
# Takes a path to an image file, with some text on it.
# Runs Windows 10 OCR against the image.
# Returns an [OcrResult], hopefully with a .Text property containing the text
# OCR part of the script from: https://github.com/HumanEquivalentUnit/PowerShell-Misc/blob/master/Get-Win10OcrTextFromImage.ps1
[CmdletBinding()]
Param
(
# Path to an image file
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
Position=0,
HelpMessage='Path to an image file, to run OCR on')]
[ValidateNotNullOrEmpty()]
$Path
)
Begin {
# [Windows.Media.Ocr.OcrEngine]::AvailableRecognizerLanguages
$ocrEngine = [Windows.Media.Ocr.OcrEngine]::TryCreateFromUserProfileLanguages()
# PowerShell doesn't have built-in support for Async operations,
# but all the WinRT methods are Async.
# This function wraps a way to call those methods, and wait for their results.
$getAwaiterBaseMethod = [WindowsRuntimeSystemExtensions].GetMember('GetAwaiter').
Where({
$PSItem.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1'
}, 'First')[0]
Function Await {
param($AsyncTask, $ResultType)
$getAwaiterBaseMethod.
MakeGenericMethod($ResultType).
Invoke($null, @($AsyncTask)).
GetResult()
}
}
Process
{
foreach ($p in $Path)
{
# From MSDN, the necessary steps to load an image are:
# Call the OpenAsync method of the StorageFile object to get a random access stream containing the image data.
# Call the static method BitmapDecoder.CreateAsync to get an instance of the BitmapDecoder class for the specified stream.
# Call GetSoftwareBitmapAsync to get a SoftwareBitmap object containing the image.
#
# https://docs.microsoft.com/en-us/windows/uwp/audio-video-camera/imaging#save-a-softwarebitmap-to-a-file-with-bitmapencoder
# .Net method needs a full path, or at least might not have the same relative path root as PowerShell
$p = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($p)
$params = @{
AsyncTask = [StorageFile]::GetFileFromPathAsync($p)
ResultType = [StorageFile]
}
$storageFile = Await @params
$params = @{
AsyncTask = $storageFile.OpenAsync([FileAccessMode]::Read)
ResultType = [Streams.IRandomAccessStream]
}
$fileStream = Await @params
$params = @{
AsyncTask = [BitmapDecoder]::CreateAsync($fileStream)
ResultType = [BitmapDecoder]
}
$bitmapDecoder = Await @params
$params = @{
AsyncTask = $bitmapDecoder.GetSoftwareBitmapAsync()
ResultType = [SoftwareBitmap]
}
$softwareBitmap = Await @params
# Run the OCR
Await $ocrEngine.RecognizeAsync($softwareBitmap) ([Windows.Media.Ocr.OcrResult])
}
}
}
# get window and sizes function
Function Get-Window {
<#
.NOTES
Name: Get-Window
Author: Boe Prox
#>
[OutputType('System.Automation.WindowInfo')]
[cmdletbinding()]
Param (
[parameter(ValueFromPipelineByPropertyName=$True)]
$ProcessName
)
Begin {
Try{
[void][Window]
} Catch {
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Window {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
}
public struct RECT
{
public int Left; // x position of upper-left corner
public int Top; // y position of upper-left corner
public int Right; // x position of lower-right corner
public int Bottom; // y position of lower-right corner
}
"@
}
}
Process {
Get-Process -Name $ProcessName | ForEach-Object {
$Handle = $_.MainWindowHandle
$Rectangle = New-Object RECT
$Return = [Window]::GetWindowRect($Handle,[ref]$Rectangle)
If ($Return) {
$Height = $Rectangle.Bottom - $Rectangle.Top
$Width = $Rectangle.Right - $Rectangle.Left
$Size = New-Object System.Management.Automation.Host.Size -ArgumentList $Width, $Height
$TopLeft = New-Object System.Management.Automation.Host.Coordinates -ArgumentList $Rectangle.Left, $Rectangle.Top
$BottomRight = New-Object System.Management.Automation.Host.Coordinates -ArgumentList $Rectangle.Right, $Rectangle.Bottom
If ($Rectangle.Top -lt 0 -AND $Rectangle.Left -lt 0) {
Write-Warning "Window is minimized! Coordinates will not be accurate."
$script:badCoords = $True
}
$Object = [pscustomobject]@{
ProcessName = $ProcessName
Size = $Size
TopLeft = $TopLeft
BottomRight = $BottomRight
}
$Object.PSTypeNames.insert(0,'System.Automation.WindowInfo')
$Object
}
}
}
}
# Notification function
function WoWNotifier {
# alert function
function Send-Alert {
# msg Discord
if ($discord) {
$discordHeaders = @{
"Content-Type" = "application/json"
}
$discordBody = @{
content = $msg
} | convertto-json
Invoke-RestMethod -Uri $discordWebHook -Method POST -Headers $discordHeaders -Body $discordBody
}
# msg Telegram
if ($telegram) {
Invoke-RestMethod -Uri "https://api.telegram.org/bot$($telegramBotToken)/sendMessage?chat_id=$($telegramChatID)&text=$($msg)"
}
# msg Pushover
if ($pushover) {
$data = @{
token = "$pushoverAppToken"
user = "$pushoverUserToken"
message = "$msg"
}
if ($device) { $data.Add("device", "$device") }
if ($title) { $data.Add("title", "$title") }
if ($priority) { $data.Add("priority", $priority) }
if ($sound) { $data.Add("sound", "$sound") }
Invoke-RestMethod "https://api.pushover.net/1/messages.json" -Method POST -Body $data
}
# text Msg
if ($textMsg) {
Send-MailMessage -SmtpServer $smtpServer -Port $smtpPort -UseSsl -Priority High -from $fromAddress -to $($phoneNumber+$CarrierEmail) -Subject "WoW Alert" -Body $msg -Credential $emailCreds
}
# msg Alexa
if ($alexa) {
$alexaBody = @{
notification = $msg
accessCode = $alexaAccessCode
} | ConvertTo-Json
Invoke-RestMethod https://api.notifymyecho.com/v1/NotifyMe -Method POST -Body $alexaBody
}
if ($HASS) {
$hassHeaders = @{
"Content-Type" = "application/json"
"Authorization"= "Bearer $hassToken"
}
$hassBody = @{
"entity_id" = $entity_ID
} | convertto-json
Invoke-RestMethod -Uri "$hassURL/api/services/script/toggle" -Method POST -Headers $hassHeaders -Body $hassBody
}
}
$script:cancelLoop = $False
$script:badCoords = $False
if ($useMyOwnCoordinates -eq "No") {
$window = Get-Process | Where-Object {$_.MainWindowTitle -like "World of Warcraft"} | Get-Window | Select-Object -First 1
$topleftX = [math]::floor($window.BottomRight.x / 3)
$topLeftY = 0
$bottomRightX = [math]::floor($topLeftX * 2)
$bottomRightY = [math]::floor($window.BottomRight.y / 2)
}
else {
$window = Get-Process | Where-Object {$_.MainWindowTitle -like "World of Warcraft"}
}
if (!($window)) {
$label_status.ForeColor = "#FF0000"
$label_status.text = "Is WoW started?"
$label_status.Refresh()
Return
}
if ($script:badCoords) {
$label_status.ForeColor = "#FF0000"
$label_status.text = "Maximize Game Window!"
$label_status.Refresh()
Return
}
$button_start.Enabled = $False
$button_start.Visible = $False
$button_stop.Enabled = $True
$button_stop.Visible = $True
$form.MinimizeBox = $False # disable while running since it breaks things
$script:label_coords_text.Visible = $False
$label_help.Visible = $False
$label_status.ForeColor = "#FFFF00"
$label_status.text = "Still In Queue ..."
$label_status.Refresh()
# default screenshot area if no coordinates specified in the above user section.
# Also tries to detect which window your game is running on, if using multiple monitors
# Get's the middle top half of the screen area to look for Queue messages
:check Do {
# check for clicks in the form since we are looping
for ($i=0; $i -lt $delay; $i++) {
[System.Windows.Forms.Application]::DoEvents()
if ($script:cancelLoop) {
$button_start.Enabled = $True
$button_start.Visible = $True
$button_stop.Enabled = $False
$button_stop.Visible = $False
$form.MinimizeBox = $True
$label_status.text = ""
$label_status.Refresh()
$script:label_coords_text.Visible = $True
$label_help.Visible = $True
Break check
}
Start-Sleep -Seconds 1
}
Get-WoWQueue
$WoWAlert = (Get-Ocr $path\WoWNotifier_Img.png).Text
# Send interval alert if enabled
if ($queueCheck -eq "Yes") {
$time = Get-Date -uformat "%M"
if ($time%$queueCheckInterval -eq 0) {
# get queue position
if ($WoWAlert -match '(?<=)\d+') {
$yourPos = $matches[0]
}
else {
$yourPos = "Unknown"
}
if ($WoWAlert -match '(?<=Estimated time.+)\d+') {
$yourEta = $matches[0]
}
else {
$yourEta = "Unknown"
}
$msg = "Position in Queue: $yourPos ETA: $yourEta min"
Send-Alert
}
}
}
Until ($WoWAlert -notlike "*Position*")
if ($script:cancelLoop) {
Return
}
# set messages
if ($WoWAlert -notlike "*Position*") {
$msg = "Game Time!"
}
# send it
Send-Alert
if ($stopOnQueue -eq "Yes") {
$label_status.ForeColor = "#7CFC00"
$label_status.text = "Game Time!"
$label_status.Refresh()
$button_stop.Enabled = $False
$button_stop.Visible = $False
$button_start.Enabled = $True
$button_start.Visible = $True
$script:label_coords_text.Visible = $True
$label_help.Visible = $True
$form.MinimizeBox = $True
}
elseif ($stopOnQueue -eq "No") {
WoWNotifier
}
}
# Form section
$form = New-Object System.Windows.Forms.Form
$form.Text ='WoW Notifier'
$form.Width = 250
$form.Height = 130
$form.AutoSize = $True
$form.MaximizeBox = $False
$form.BackColor = "#4a4a4a"
$form.TopMost = $False
$form.StartPosition = 'CenterScreen'
$form.FormBorderStyle = "FixedDialog"
# Start Button
$button_start = New-Object system.Windows.Forms.Button
$button_start.BackColor = "#f5a623"
$button_start.text = "START"
$button_start.width = 120
$button_start.height = 50
$button_start.location = New-Object System.Drawing.Point(62,15)
$button_start.Font = 'Microsoft Sans Serif,9,style=Bold'
$button_start.FlatStyle = "Flat"
# Stop Button
$button_stop = New-Object system.Windows.Forms.Button
$button_stop.BackColor = "#f5a623"
$button_stop.ForeColor = "#FF0000"
$button_stop.text = "STOP"
$button_stop.width = 120
$button_stop.height = 50
$button_stop.location = New-Object System.Drawing.Point(62,15)
$button_stop.Font = 'Microsoft Sans Serif,9,style=Bold'
$button_stop.FlatStyle = "Flat"
$button_stop.Enabled = $False
$button_stop.Visible = $False
# Status label
$label_status = New-Object system.Windows.Forms.Label
$label_status.text = ""
$label_status.AutoSize = $True
$label_status.width = 30
$label_status.height = 20
$label_status.location = New-Object System.Drawing.Point(60,75)
$label_status.Font = 'Microsoft Sans Serif,10,style=Bold'
$label_status.ForeColor = "#7CFC00"
# Coords label text
$script:label_coords_text = New-Object system.Windows.Forms.LinkLabel
$script:label_coords_text.text = "Get Coords"
$script:label_coords_text.AutoSize = $True
$script:label_coords_text.width = 30
$script:label_coords_text.height = 20
$script:label_coords_text.location = New-Object System.Drawing.Point(5,100)
$script:label_coords_text.Font = 'Microsoft Sans Serif,9,'
$script:label_coords_text.ForeColor = "#00ff00"
$script:label_coords_text.LinkColor = "#f5a623"
$script:label_coords_text.ActiveLinkColor = "#f5a623"
$script:label_coords_text.add_Click({Get-Coords})
# Coords label text exit
$script:label_coords_text2 = New-Object system.Windows.Forms.LinkLabel
$script:label_coords_text2.text = "Exit Coords"
$script:label_coords_text2.AutoSize = $True
$script:label_coords_text2.width = 30
$script:label_coords_text2.height = 20
$script:label_coords_text2.location = New-Object System.Drawing.Point(5,100)
$script:label_coords_text2.Font = 'Microsoft Sans Serif,9,'
$script:label_coords_text2.ForeColor = "#00ff00"
$script:label_coords_text2.LinkColor = "#f5a623"
$script:label_coords_text2.ActiveLinkColor = "#f5a623"
$script:label_coords_text2.Visible = $False
$script:label_coords_text2.add_Click({
$script:cancelLoop = $True
$script:label_coords1.Visible = $False
$script:label_coords2.Visible = $False
$button_start.Visible = $True
$script:label_coords1.Text = ""
$script:label_coords1.Refresh()
$script:label_coords2.Text = ""
$script:label_coords2.Refresh()
$script:label_coords_text2.Visible = $False
$script:label_coords_text.Visible = $True
$script:label_coords_text.Enabled = $True
$script:label_coords_text2.Enabled = $False
$form.TopMost = $False
})
# Coords label top left
$script:label_coords1 = New-Object system.Windows.Forms.Label
$script:label_coords1.Text = ""
$script:label_coords1.AutoSize = $True
$script:label_coords1.width = 30
$script:label_coords1.height = 20
$script:label_coords1.location = New-Object System.Drawing.Point(10,15)
$script:label_coords1.Font = 'Microsoft Sans Serif,10,style=Bold'
$script:label_coords1.ForeColor = "#f5a623"
# Coords label bottom right
$script:label_coords2 = New-Object system.Windows.Forms.Label
$script:label_coords2.Text = ""
$script:label_coords2.AutoSize = $True
$script:label_coords2.width = 30
$script:label_coords2.height = 20
$script:label_coords2.location = New-Object System.Drawing.Point(10,40)
$script:label_coords2.Font = 'Microsoft Sans Serif,10,style=Bold'
$script:label_coords2.ForeColor = "#f5a623"
# Help link
$label_help = New-Object system.Windows.Forms.LinkLabel
$label_help.text = "Help"
$label_help.AutoSize = $true
$label_help.width = 70
$label_help.height = 20
$label_help.location = New-Object System.Drawing.Point(210,100)
$label_help.Font = 'Microsoft Sans Serif,9'
$label_help.ForeColor = "#00ff00"
$label_help.LinkColor = "#f5a623"
$label_help.ActiveLinkColor = "#f5a623"
$label_help.add_Click({[system.Diagnostics.Process]::start("http://github.com/ninthwalker/WoWNotifier")})
# add all controls
$form.Controls.AddRange(($button_start,$button_stop,$label_status,$script:label_coords_text,$script:label_coords_text2,$script:label_coords1,$script:label_coords2,$label_help))
# Button methods
$button_start.Add_Click({WoWNotifier})
$button_stop.Add_Click({
if (Test-Path $path\WoWNotifier_Img.png) {
Remove-Item $path\WoWNotifier_Img.png -Force -Confirm:$False
}
$script:cancelLoop = $True
})
# catch close handle
$form.add_FormClosing({
if (Test-Path $path\WoWNotifier_Img.png) {
Remove-Item $path\WoWNotifier_Img.png -Force -Confirm:$False
}
$script:cancelLoop = $True
})
# show the forms
$form.ShowDialog()
# close the forms
$form.Dispose()