forked from OpenMultiBoxing/OpenMultiBoxing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenMultiBoxing.tcl
More file actions
3592 lines (3373 loc) · 121 KB
/
OpenMultiBoxing.tcl
File metadata and controls
3592 lines (3373 loc) · 121 KB
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
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# WowOpenBox / OpenMultiboxing by MooreaTV <moorea@ymail.com> (c) 2020-2023 All rights reserved
# Open Source Software licensed under GPLv3 - No Warranty
# (contact the author if you need a different license)
#
# The GNU General Public License does not permit incorporating this work
# into proprietary programs.
#
# Releases detail/changes are on https://github.com/OpenMultiBoxing/OpenMultiBoxing/releases
#
package require Tk
package require twapi
package require http
package require twapi_crypto
http::register https 443 ::twapi::tls_socket
package require tooltip
package require tkdnd
namespace import tooltip::tooltip
# tkk native
ttk::style theme use winnative
# start not showing top level for error dialogs
wm state . withdrawn
# Update in progress detected
array set updateCheck {}
catch {array set updateCheck [info frame -1]}
if {[info exists updateCheck(proc)] && $updateCheck(proc)=="::CheckForUpdates"} {
puts stderr "Update detected!"
set isUpdate 1
# keep oldVersion as the binary/bootstrap's version even in update
if {![info exists oldVersion]} {
set oldVersion $vers
}
set previousVersion $vers
# cancel all background tasks
after cancel [after info]
} else {
set isUpdate 0
if {[info exists vers] && ![info exists oldVersion]} {
set oldVersion $vers
}
}
set vers "dev"
proc Debug {msg} {
global settings forceDebug
if {$forceDebug || $settings(DEBUG)} {
puts "DEBUG $msg"
}
}
proc EnableDisableWindows {enable} {
if {$enable} {
catch {tk busy forget .layout}
catch {tk busy forget .overlayConfig}
catch {tk busy forget .}
} else {
catch {tk busy hold .}
catch {tk busy hold .overlayConfig}
catch {tk busy hold .layout}
update
}
}
proc OmbMessage {args} {
global hotkeyOk
set hotkeyOk 0
Debug "OMB message $args"
EnableDisableWindows 0
set ret [tk_messageBox {*}$args]
EnableDisableWindows 1
set hotkeyOk 1
return $ret
}
proc OmbError {title msg} {
puts stderr "Error $title: $msg"
OmbMessage -type ok -icon error -title $title -message $msg
}
set SETTINGS_PREFIX "OpenMultiBoxingSettings"
set SETTINGS_SUFFIX ".tcl"
set SETTINGS_BASE "$SETTINGS_PREFIX$SETTINGS_SUFFIX"
# RR init upgrade aware
set rrOn 0
if {![info exists hasRR]} {
set hasRR 0
}
proc HasArg {argName} {
global argv
expr {[lsearch $argv $argName]!=-1}
}
if {![info exists wobInitDone]} {
set wobInitDone 1
set forceDebug 0
array set settings {DEBUG 0}
if {[HasArg "-debug"]} {
set forceDebug 1
catch {console show}
Debug "OMB $vers called with -debug"
}
if {[HasArg "-rr"]} {
set hasRR 1
Debug "OMB $vers called with -rr (hopefully from OpenMultiBoxing_RR.exe)"
}
if {[HasArg "-profile"]} {
set initProfile [lindex $argv end]
Debug "OMB requested profile '$initProfile'"
}
# Settings and updated code directory
# -- App utils - save settings
set script_path [file normalize [info script]]
set app_dir [file dirname $script_path]
set img_dir [file dirname $script_path]
set script_name [file tail $script_path]
Debug "Original app_dir: $app_dir (script [info script])"
# Normalize appdir in case we're inside the binary
set inExe [regsub -nocase {/[^/]+\.exe/app$} $app_dir {} app_dir]
Debug "Post exe detection app_dir: $app_dir"
set SETTINGS_FILE [file join $app_dir $SETTINGS_BASE]
set update_path [file join $app_dir $script_name]
Debug "Base settings: $SETTINGS_FILE"
if {$inExe} {
# We're inside the exe, check for updated code
Debug "In EXE, checking for code outside: $update_path"
if {[file readable $update_path]} {
if {[catch {source -encoding utf-8 $update_path} err]} {
OmbError "OMB error: update file error" \
"Please delete [file nativename $update_path] and restart\n\n$err\n$errorInfo"
exit 1
} else {
Debug "Control passed to local file $update_path"
return
}
}
}
}
proc CheckForUpdates {silent} {
global vers update_path settings errorInfo
set url "https://api.github.com/repos/OpenMultiBoxing/OpenMultiBoxing/releases/latest"
if {[catch {set token [http::geturl $url]} err]} {
OmbError "OpenMultiBoxing network error" "Url fetch error $err"
return
}
set settings(lastUpdateChecked) [clock seconds]
SaveSettings
set body [http::data $token]
if {[string match "*/tag/$vers\",*" $body]} {
if {$silent} {
Debug "Already running latest $vers"
return
}
OmbMessage -type ok -icon info -title "Already uptodate" \
-message "You're already running the latest version $vers"
return
}
if {![regexp {browser_download_url":"(https://github\.com/OpenMultiBoxing/OpenMultiBoxing/releases/download/[^"]+\.tcl)"} $body all updateUrl]} {
Debug "--- Update not found in $url ---\n$body\n--- end of $url ---"
OmbError "Update Error" "Couldn't find update in latest release - please report as a bug"
return
}
set name ""
set description ""
regexp {"name":"(.*?)",} $body all name
regexp "\"body\":\"(.*?)\"(,|\})" $body all description
regsub -all {\\r} $description "" description
regsub -all {\\n} $description "\n" description
set description [string trimright $description]
Debug "Found update $updateUrl : $name ($description)"
if {![regexp {/(v[^/]+)/} $updateUrl all newVersion]} {
OmbError "Update Error" "Couldn't find version in update url: $updateUrl\nPlease report this bug!"
return
}
set doUpdate [OmbMessage -type yesno -icon question -title "Update Available" \
-message "$newVersion is available:\n\n$name\n\n$description\n\nDo you want to install it?"]
Debug "Do update is $doUpdate"
if {$doUpdate=="no"} {
return
}
if {[catch {set token [http::geturl $updateUrl]} err]} {
OmbError "Update error" "Update fetch error for\n$updateUrl\n$err"
return
}
set ncode [http::ncode $token]
if {$ncode == 301 || $ncode == 302} {
upvar #0 $token state
array set meta $state(meta)
set location "not-found!"
if {[info exists meta(Location)]} {
set location $meta(Location)
}
if {[info exists meta(location)]} {
set location $meta(location)
}
Debug "Got a redirect $ncode: $location"
if {[catch {set token [http::geturl $location]} err]} {
OmbError "Update error" "Update fetch error for redirected\n$location\n$err"
return
}
set ncode [http::ncode $token]
}
if {$ncode != 200} {
OmbError "Update error" "Update error code $ncode for\n$updateUrl"
return
}
set body [http::data $token]
set backup_path ${update_path}.$vers.bak
# delete older backups
catch {file delete {*}[glob ${update_path}.*.bak]}
# can error when in exe...
catch {file rename -force $update_path $backup_path}
set f [open $update_path w+]
fconfigure $f -translation binary
puts -nonewline $f $body
close $f
Debug "Updated $update_path"
OmbMessage -type ok -icon info -title "Download complete" \
-message "Backed up previous version as $backup_path - ready to restart with $newVersion"
if {[catch {uplevel #0 [list source -encoding utf-8 $update_path]} err]} {
OmbError "Update error" "Error in new downloaded script:\n$err\n$errorInfo\n\nPlease screenshot this and report this bug!"
return
}
Debug "Control passed successfully to updated file $newVersion"
}
# -- UI
proc NewProfile {} {
global settings profileName
set t .newProfile
set profileName {}
EnableDisableWindows 0
toplevel $t
wm resizable $t 0 0
wm title $t "OMB New Profile Name..."
ttk::label $t.l -text "Save settings as new Profile named:"
ttk::entry $t.e -textvar profileName
bind $t.e <Return> {set doneDialog 1}
ttk::button $t.ok -text OK -command {set doneDialog 1}
ttk::button $t.cancel -text Cancel -command "set profileName {}; set doneDialog 1"
bind $t.e <Escape> "$t.cancel invoke"
grid $t.l - -sticky news -padx 4 -pady 4
grid $t.e - -sticky news -padx 4 -pady 4
grid $t.ok $t.cancel -padx 4 -pady 4
focus $t.e
UpdateHandles
vwait doneDialog
destroy $t
EnableDisableWindows 1
if {$profileName!=""} {
Debug "New profile dialog returned $profileName"
set settings(profile) $profileName
SaveSettings
} else {
Debug "New profile cancelled"
}
}
proc ProfileFileName {profile} {
global app_dir SETTINGS_PREFIX SETTINGS_SUFFIX
set p $profile
if {$p=="Default"} {
set p ""
}
set path [file join $app_dir "$SETTINGS_PREFIX$p$SETTINGS_SUFFIX"]
Debug "For profile $profile path: $path"
return $path
}
proc RefreshProfiles {} {
global app_dir SETTINGS_PREFIX SETTINGS_SUFFIX settings
set settings(profiles) [list "Default"]
foreach fn [glob [file join $app_dir "${SETTINGS_PREFIX}*${SETTINGS_SUFFIX}"]] {
# suffix starts with a . so \ it
set p ""
regexp "^.*${SETTINGS_PREFIX}(.*)\\${SETTINGS_SUFFIX}$" $fn all p
Debug "Found file $fn -> $p"
if {$p==""} {
continue
}
lappend settings(profiles) $p
}
if {[lsearch -exact $settings(profiles) $settings(profile)] == -1} {
OmbError "Profile error" "Profile $settings(profile) not found; resetting to Default"
set settings(profile) "Default"
}
UpdateProfilesMenu
LoadProfile
}
proc SaveSettings {args} {
global SETTINGS_FILE settings app_dir isPaused prevOL
if {$isPaused && $prevOL} {
set settings(showOverlay) 1
}
set p $settings(profile)
if {$p!="Default"} {
Debug "SaveSettings for profile $p"
if {[lsearch $settings(profiles) $p]==-1} {
Debug "New profile $p"
lappend settings(profiles) $p
.mbar.profile insert 1 radiobutton -label $p -variable settings(profile) -command LoadProfile
}
set pMode 1
set pf [ProfileFileName $p]
set f [open $pf w+]
fconfigure $f -encoding utf-8
puts $f "array set settings {"
foreach i [lsort [array names settings]] {
if {$i=="profile" || $i=="profiles" || $i=="games" || $i=="lastUpdateChecked"} {
continue
}
# Debug "saving $i \"$settings($i)\""
puts $f "\t$i\t[list $settings($i)]"
}
puts $f "}"
close $f
}
Debug "SaveSettings base $SETTINGS_FILE (from cb $args)"
if {[catch {open $SETTINGS_FILE w+} f]} {
OmbError "Error saving settings" \
"Unable to save settings: $f\n\nPlease do not put OpenMultiBoxing*.exe\nin a system/special/protected folder\nput them on your Desktop instead for instance."
return
}
fconfigure $f -encoding utf-8
puts $f "array set settings {"
foreach i [lsort [array names settings]] {
# Debug "saving $i \"$settings($i)\""
puts $f "\t$i\t[list $settings($i)]"
}
puts $f "}"
close $f
}
proc LoadProfile {} {
global settings
set profile $settings(profile)
set pf [ProfileFileName $profile]
if {[catch {source -encoding utf-8 $pf} err]} {
puts stderr "Error sourcing profile $pf\n$err"
OmbError "OpenMultiBoxing profile error" \
"Your $pf has an error: $err\nYou can remove it and use Refresh Profiles in the menu."
set settings(profile) "Default"
return
}
# Otherwise can be reset when switching from Profile N back to Default
set settings(profile) $profile
AfterSettings
ResetAll
}
proc LoadSettings {} {
global SETTINGS_FILE settings app_dir
if {[winfo exists .b1]} {
.b1 configure -text "Edit Settings" -command EditSettings
}
if {[file exists $SETTINGS_FILE]} {
if {[catch {source -encoding utf-8 $SETTINGS_FILE} err]} {
puts stderr "Could not source $SETTINGS_FILE\n$err"
OmbError "OpenMultiBoxing settings error" \
"Your $SETTINGS_FILE has an error: $err"
} else {
if {$settings(profile)!="Default"} {
LoadProfile
}
}
}
AfterSettings
}
proc UnregisterHotkeys {} {
global allHotKeys
Debug "Unregistering previous hotkeys"
foreach hk $allHotKeys {
twapi::unregister_hotkey $hk
}
}
proc IsInside {x y x1 y1 x2 y2} {
expr {$x>=$x1 && $x<=$x2 && $y>=$y1 && $y<=$y2}
}
proc Offscreen {x y} {
global displayInfo
if {![info exists displayInfo]} {
# only extract it the first time
set displayInfo [twapi::get_multiple_display_monitor_info]
Debug "displayInfo = $displayInfo"
}
set i 0
foreach monitor $displayInfo {
incr i 1
array set info $monitor
lassign $info(-extent) x1 y1 x2 y2
Debug "Monitor $i Extent $x1,$y1 - $x2,$y2"
if {[IsInside $x $y $x1 $y1 $x2 $y2]} {
return false
}
}
return true
}
proc OffscreenGeometryCheck {} {
global settings
foreach k {mainWindowGeometry clipGeometry} {
if {![info exists settings($k)]} {
continue
}
regexp {\+(.*?)\+(.*?)$} $settings($k) all x y
Debug "geometry for $k is at $x,$y"
if {[Offscreen $x $y]} {
Debug "unsetting offscreen geometry $k"
unset settings($k)
}
}
}
proc AfterSettings {} {
global settings maxNumW slot2handle
# Handle off screen/geometry change
OffscreenGeometryCheck
if {$settings(hk,swapNextWindow)=="Binding for next window swap is set on 'hk1,swap'"} {
set settings(hk,swapNextWindow) "Ctrl-0xC0"
}
if {$settings(rrInterval) == 50} {
set settings(rrInterval) 5
}
if {[info exists settings(rrKeyList)]} {
# convert to space separated from tcl list
set settings(rrKeyListAll) [join $settings(rrKeyList) " "]
set settings(rrModExcludeList) [join $settings(rrModExcludeList) " "]
unset settings(rrKeyList)
}
set toAdd "SndVol.exe"
if {[lsearch -exact $settings(dontCaptureList) $toAdd]==-1} {
lappend settings(dontCaptureList) $toAdd
}
if {[info exists settings(overlayBig)]} {
if {!$settings(overlayBig)} {
set settings(overlayFontSize2) $settings(overlayFontSize1)
}
unset settings(overlayBig)
}
UnregisterHotkeys
RegisterHotkey "Capture" hk,capture CaptureOrUpdate
RegisterHotkey "Start/Stop mouse tracking" hk,mouseTrack MouseTracking
RegisterHotkey "Focus next window" hk,focusNextWindow FocusNextWindow
RegisterHotkey "Focus previous window" hk,focusPreviousWindow FocusPreviousWindow
RegisterHotkey "Swap next window" hk,swapNextWindow SwapNextWindow
RegisterHotkey "Swap previous window" hk,swapPreviousWindow SwapPreviousWindow
RegisterHotkey "Focus follow mouse toggle" hk,focusFollowMouse FocusFollowMouseToggle
RegisterHotkey "Always on top toggle" hk,stayOnTopToggle StayOnTopToggle
RegisterHotkey "Overlay toggle" hk,overlayToggle OverlayToggle
RegisterHotkey "RoundRobin toggle" hk,rrToggle RRToggle
RegisterHotkey "Focus main window" hk,focusMain FocusMain
RegisterHotkey "Reset all windows to saved positions" hk,resetAll ResetAll
RegisterHotkey "Start/Stop mouse broadcasting" hk,mouseBroadcast MouseBroadcast
for {set n 1} {$n < $maxNumW} {incr n} {
if {[info exists slot2handle($n)]} {
RegisterPerWindowHotkey $n "OMB $n"
}
}
# Set mouse control to current values
global mouseFollow mouseRaise mouseDelay
set mouseDelay [GetMouseDelay]
set mouseFollow [GetFocusFollowMouse]
set mouseRaise [GetMouseRaise]
LoadLayout
Overlay
RRCustomMenu
Debug "Settings (re)Loaded."
}
set prevMF 0
proc RevertMouseFollow {} {
global mouseDelay settings prevMF mouseFollow
if {!$settings(mouseFocusOffAtExit)} {
if {$prevMF} {
Debug "Keeping mouse focus mode on on exit"
set mouseFollow 1
UpdateMouseFollow
}
return
}
if {![info exists mouseDelay]} {
set mouseDelay 200
}
Debug "restoring mouse delay $mouseDelay"
SetMouseDelay $mouseDelay
SetFocusFollowMouse 0
}
catch {rename exit _real_exit}
wm protocol . WM_DELETE_WINDOW exit
proc exit {{status 0}} {
Debug "Exit $status called"
catch {destroy .clip}
after cancel [after info]
RevertMouseFollow
update
after cancel [after info]
_real_exit $status
}
proc FocusFollowMouseToggle {} {
Debug "Follow mouse toggle requested"
.mf configure -state enabled
.mf invoke
}
proc updateIndex {args} {
global nextWindow maxNumW pos windowSize stayOnTop settings slot2handle
Debug "nextWindow is $nextWindow - args $args"
if {[info exists settings($nextWindow,size)]} {
set windowSize $settings($nextWindow,size)
set pos $settings($nextWindow,posXY)
if {[info exists settings($nextWindow,stayOnTop)]} {
set stayOnTop $settings($nextWindow,stayOnTop)
}
}
.csop configure -text "Wow window $nextWindow always on top"
if {$nextWindow<$maxNumW} {
.l2 configure -text "Selected :"
} else {
.l2 configure -text "Next window :"
}
if {[info exists slot2handle($nextWindow)]} {
.b2 configure -text " Update " -state enabled
} else {
.b2 configure -text " Capture "
UpdateForegroundMode
}
}
proc GetLogo {} {
global imgOMB70 vers inExe img_dir
if {[catch {set imgOMB70 [image create photo -file [file join $img_dir "OpenMultiBoxing70.png"]]} err]} {
Debug "Didn't get logos: $err - falling back to https download"
} else {
Debug "In exe omb logo loaded"
return ""
}
if {[catch {set token [http::geturl "https://openmultiboxing.org/OpenMultiBoxing70.png?v=$vers"]} err]} {
OmbError "OpenMultiBoxing network error" "Url fetch error $err"
return $err
}
set body [http::data $token]
if {[catch {set imgOMB70 [image create photo -data $body]} err]} {
OmbError "Open Multi Boxing logo error" "Logo error $err -:- $body"
return "Invalid data $err $body"
}
return ""
}
set ourTitle "OpenMultiBoxing - Opensource MultiBoxing"
proc UISetup {} {
global imgOMB70 vers stayOnTop pos windowSize settings \
mouseFollow mouseRaise mouseDelay ourTitle bottomText \
rrOn hasRR mouseBroadcast
wm title . $ourTitle
# Get logo
set err [GetLogo]
if {$err != ""} {
set txt "Opensource\nMulti\nBoxing"
grid [ttk::label .logo -text $txt] -rowspan 3
} else {
grid [ttk::label .logo] -rowspan 3 -pady 6 -padx 12
.logo configure -image $imgOMB70
wm iconphoto . -default $imgOMB70
}
set labelW 18
grid [ttk::button .bH -text "Help" -width $labelW -command Help] -row 0 -column 1 -padx 4
tooltip .bH "Opens online help page"
grid [ttk::button .bwl -text "Window Layout" -width $labelW -command WindowLayout] -row 1 -column 1
tooltip .bwl "View or change the Window Layout"
grid [ttk::button .b1 -text "Edit Settings" -width $labelW -command EditSettings] -row 2 -column 1
tooltip .b1 "Opens the editor to edit settings\nand reload them after save.\nLet's you change hotkeys like:\nSwap next window: $settings(hk1,swap)\nFocus next window: $settings(hk,focusNextWindow)\netc... See Help for details."
# label width - enough to fit "-9999 -9999"
set width 10
grid [frame .sep1 -relief groove -borderwidth 2 -width 2 -height 2] -sticky ew -padx 4 -pady 4 -columnspan 2
grid [ttk::label .l2 -text "Next window :" -anchor e] [entry .e1 -textvariable nextWindow -width $width] -padx 4 -sticky ew
bind .e1 <FocusIn> [list focusIn %W]
grid [ttk::label .l3 -text "Resize to" -anchor e] [entry .e2 -textvariable windowSize -width $width] -padx 4 -sticky ew
grid [ttk::label .l4 -text "Move to" -anchor e] [entry .e3 -textvariable pos -width $width] -padx 4 -sticky ew
grid [ttk::checkbutton .csop -text "Wow window always on top" -variable stayOnTop] -columnspan 2
tooltip .csop "Whether that window should be on top of others.\nThis can be changed at anytime for the current focused window\nusing the Hotkey: $settings(hk,stayOnTopToggle)"
grid [ttk::button .b2 -text " Capture " -command CaptureOrUpdate] -pady 5 -columnspan 2
tooltip .b2 "Capture or update window\nHotkey: $settings(hk,capture)"
grid [listbox .lbw -height 6] -columnspan 2 -sticky ns
bind .lbw <<ListboxSelect>> [list selectChanged %W]
grid [ttk::checkbutton .cbCaptureFG -text "Capture using foreground window" -command UpdateForegroundMode -variable settings(captureForegroundWindow)] -columnspan 2
tooltip .cbCaptureFG "Instead of capturing the game window by name\n($settings(game))\nif checked, capture the current foreground window\nFor this to work you must use the hotkey:\n$settings(hk,capture)\n\nUse the Game menu to turn this on"
UpdateForegroundMode
grid [ttk::checkbutton .cboverlay -text "Show overlay" -variable settings(showOverlay) -command "OverlayUpdate; SaveSettings"] [ttk::button .cbocfg -text "Overlay config" -command OverlayConfig]
tooltip .cboverlay "Show/Hide the overlay info\nHotkey: $settings(hk,overlayToggle)"
tooltip .cbocfg "Opens the overlay config which let's you configure\nborder, color, positions, etc... for the overlay"
if {$hasRR} {
grid [frame .sepRR -relief groove -borderwidth 2 -width 2 -height 2] -sticky ew -padx 4 -pady 4 -columnspan 2
grid [ttk::label .lRR -text "⟳ Round robin settings:" -font "*-*-bold" -anchor sw] -padx 4 -columnspan 2 -sticky w
grid [ttk::checkbutton .cbRR -text "Round Robin ($settings(hk,rrToggle))" -variable rrOn -command RRUpdate] -padx 4 -columnspan 2 -sticky w
tooltip .cbRR "Toggle round robin mode\nAlso turns off mouse focus and restore as needed while on\nHotkey: $settings(hk,rrToggle)"
grid [ttk::label .lrrK -text "Round Robin to all windows keys:"] -padx 4 -columnspan 2 -sticky w
grid [entry .eRR -textvariable settings(rrKeyListAll) -width $width] -columnspan 2 -padx 4 -sticky ew
bind .eRR <Return> RRKeysListChange
tooltip .eRR "Which keys trigger round robin for all windows\nHit <Return> after change to take effect.\nSee help/FAQ for list."
grid [ttk::label .lrrK2 -text "No Round Robin when:"] -padx 4 -columnspan 2 -sticky w
grid [entry .eRR2 -textvariable settings(rrModExcludeList) -width $width] -columnspan 2 -padx 4 -sticky ew
tooltip .eRR2 "Which modifiers pause round robin while held\nHit <Return> after change to take effect.\nSee help/FAQ for list."
bind .eRR2 <Return> RRKeysListChange
set rrC .rrC
frame $rrC
ttk::menubutton $rrC.rrMenuB -text "Skips" -menu $rrC.rrMenuB.menu
menu $rrC.rrMenuB.menu -tearoff 0
RRCustomMenu
tooltip $rrC.rrMenuB "Select which window(s) are excluded from custom rotation"
pack [ttk::label $rrC.lrrK3 -text "Custom rotation keys:" -anchor w] $rrC.rrMenuB -anchor w -side left -expand 1
grid $rrC -padx 4 -columnspan 2 -sticky ew
grid [entry .eRR3 -textvariable settings(rrKeyListCustom) -width $width] -columnspan 2 -padx 4 -sticky ew
tooltip .eRR3 "Which keys trigger custom rotation round robin\nHit <Return> after change to take effect.\nSee help/FAQ for list."
bind .eRR3 <Return> RRKeysListChange
grid [ttk::label .lrrD -text "Direct focus keys (Main, WOB1...N):"] -padx 4 -columnspan 2 -sticky w
grid [entry .eRR4 -textvariable settings(rrKeyListDirect) -width $width] -columnspan 2 -padx 4 -sticky ew
tooltip .eRR4 "Which key will switch focus asap directly to Main, WOB1, WOB2,...\nFirst key will focus main, 2nd key will focus WOB1, 3rd key will focus WOB2,...\nTo skip a slot position use .*\nRemember this is in addition to the focus hotkeys.\nHit <Return> after change to take effect.\nSee help/FAQ for list."
bind .eRR4 <Return> RRKeysListChange
}
grid [frame .sep2 -relief groove -borderwidth 2 -width 2 -height 2] -sticky ew -padx 4 -pady 4 -columnspan 2
grid [ttk::label .l6 -text "🖰 Mouse settings:" -font "*-*-bold" -anchor sw] -padx 4 -columnspan 2 -sticky w
grid [ttk::checkbutton .mf -text "Focus follows mouse" -variable mouseFollow -command UpdateMouseFollow] -padx 4 -columnspan 2 -sticky w
tooltip .mf "Toggle focus follow mouse mode\nHotkey: $settings(hk,focusFollowMouse)"
grid [ttk::checkbutton .mbc -text "Broadcast mouse clicks" -variable mouseBroadcast] -padx 4 -columnspan 2 -sticky w
tooltip .mbc "Toggle mouse click broadcasting\nHotkey: $settings(hk,mouseBroadcast)"
grid [ttk::label .l_bottom -textvariable bottomText -justify center -anchor c] -padx 2 -columnspan 2
bind .l_bottom <ButtonPress> [list CheckForUpdates 0]
tooltip .l_bottom "Click to check for update from $vers"
grid rowconfigure . 9 -weight 1
grid columnconfigure . 1 -weight 1
}
proc UpdateForegroundMode {} {
global settings
if {$settings(captureForegroundWindow)} {
.cbCaptureFG configure -state enabled
if {[string match "*Capture*" [.b2 configure -text]]} {
.b2 configure -state disabled
}
} else {
.b2 configure -state enabled
.cbCaptureFG configure -state disabled
}
}
proc About {} {
global vers hasRR inExe oldVersion
if {$hasRR} {
set extra "(with RoundRobin enabled)"
} else {
set extra "(without RoundRobin, launch OpenMultiBoxing_RR-${vers}.exe to enable)."
}
if {$inExe && [info exists oldVersion] && $oldVersion !=$vers} {
set extra "Binary version $oldVersion\n$extra"
}
OmbMessage -type ok -icon info -title "About OpenMultiBoxing" \
-message \
"Open MultiBoxing (OMB) $vers\n$extra\n\nFree, OpenSource, Safe, Rules compliant, Multiboxing Software\n\nLicensed under GPLv3 - No Warranty\nThe GNU General Public License does not permit incorporating this work into proprietary programs.\n\nhttps://openmultiboxing.org https://wowopenbox.org/\n\uA9 2020-2021 MooreaTv <moorea@ymail.com>"
}
#### Start of clipboard management ####
# A bit more secure than notepad clipboard copy/paste option
set clipboardValue {}
proc ClearClipboard {} {
global clipboardValue
Debug "Clearing clipboard!"
set clipboardValue {}
clipboard clear
clipboard append -- ""
}
proc SetClipboard {} {
global clipboardValue
clipboard clear
clipboard append -- $clipboardValue
}
proc BroadcastClipboard {} {
global clipboardValue
BroadcastText "$clipboardValue" 1
ClearClipboard
twapi::set_foreground_window [twapi::tkpath_to_hwnd .clip]
}
proc ClipboardManager {} {
global clipboardValue rrOn hasRR settings
set tw .clip
if {[winfo exists $tw]} {
wm state $tw normal
raise $tw
return
}
toplevel $tw
wm title $tw "OMB Secure Copy Paste"
grid [ttk::label $tw.la -text "Secure text"] [entry $tw.e -show "*" -textvariable clipboardValue -width 14] -padx 4 -sticky ew
grid [ttk::button $tw.broadcast -width 14 -text "Broadcast" -command BroadcastClipboard] - -padx 4 -sticky ew
grid [ttk::button $tw.copy -width 14 -text "Copy" -command SetClipboard] [ttk::button $tw.clear -width 14 -text "Clear" -command ClearClipboard] -padx 4 -sticky ew
tooltip $tw.copy "Copy hidden text"
tooltip $tw.clear "Clear clipboard and hidden text"
bind $tw.clear <Destroy> ClearClipboard
grid [ttk::label $tw.help -text "Type in the entry box, only *s will show,\nType <Return> for broadcast or\nClick Copy, then Ctrl-V as many times to paste,\nClose this popup or click Clear to erase."] -padx 4 -pady 6 -columnspan 2
UpdateHandles
focus $tw.e
bind $tw.e <Return> BroadcastClipboard
if {[info exists settings(clipGeometry)]} {
catch {wm geometry .clip $settings(clipGeometry)}
}
bind .clip <Configure> {set settings(clipGeometry) [wm geometry .clip]}
}
#### end of clipboard management ####
proc CloseAllGames {{andExit 0}} {
global slot2handle slot2position nextWindow maxNumW
set extraMsg ""
if {$andExit} {
set extraMsg " and Exit OMB"
}
set r [OmbMessage -type yesno -title "Close All$extraMsg?" -icon warning -default no\
-message "Are you sure you want to (force) close all the game windows$extraMsg?\n\nYou will lose all unsaved progress!"]
if {$r!="yes"} {
Debug "Close All not confirmed"
return
}
Debug "Close all confirmed"
foreach {n w} [array get slot2handle] {
catch {twapi::close_window $w}
}
if {$andExit} {
exit 0
}
# reset for recapture
array unset slot2handle
array unset slot2position
.lbw delete 0 end
set nextWindow 1
set maxNumW 1
}
proc UpdateProfilesMenu {} {
global settings
set m2 .mbar.profile
$m2 delete 0 end
foreach p $settings(profiles) {
$m2 add radiobutton -label $p -variable settings(profile) -command LoadProfile
}
$m2 add separator
$m2 add command -label "Refresh Profiles" -command RefreshProfiles
}
proc MenuSetup {} {
global vers settings hasRR mouseRaise
if {[winfo exists .mbar]} {
return
}
menu .mbar -type menubar
. configure -menu .mbar
set m1 .mbar.file
menu $m1 -tearoff 0
.mbar add cascade -label File -menu $m1
$m1 add command -label "New Profile..." -command NewProfile
$m1 add command -label "Edit raw settings..." -command EditSettings
$m1 add command -label "Save settings" -command SaveSettings
$m1 add command -label "Reload settings" -command LoadSettings
$m1 add separator
$m1 add command -label "Clipboard copy/paster..." -command ClipboardManager
$m1 add separator
$m1 add command -label "Reset all windows ($settings(hk,resetAll))" -command ResetAll
$m1 add separator
$m1 add command -label "Close all games..." -command CloseAllGames
$m1 add command -label "Close all games and Exit..." -command "CloseAllGames 1"
$m1 add separator
$m1 add command -label "Save and Exit" -command "SaveSettings; exit 0"
$m1 add command -label "Exit" -command "exit 0"
set mG .mbar.game
menu $mG -tearoff 0
.mbar add cascade -label Game -menu $mG
foreach g $settings(games) {
$mG add radiobutton -label $g -value $g -variable settings(game)
}
$mG add separator
$mG add checkbutton -label "Add (capture focused window mode)" -variable settings(captureForegroundWindow) -command UpdateForegroundMode
set m2 .mbar.profile
menu $m2 -tearoff 0
.mbar add cascade -label Profile -menu $m2
UpdateProfilesMenu
set m3 .mbar.options
menu $m3 -tearoff 0
.mbar add cascade -label Option -menu $m3
$m3 add checkbutton -label "Swap hotkey also focuses" -variable settings(swapAlsoFocus)
if {!$hasRR} {
$m3 add checkbutton -label "Focus hotkey also foregrounds" -variable settings(focusAlsoFG)
}
$m3 add checkbutton -label "Auto Capture Game windows" -variable settings(autoCapture)
$m3 add checkbutton -label "Capture makes windows borderless" -variable settings(borderless)
$m3 add checkbutton -label "Auto Kill \"$settings(autoKillName)\"" -variable settings(autoKillOn)
$m3 add checkbutton -label "Mouse auto foreground window" -variable mouseRaise -command UpdateMouseRaise
$m3 add checkbutton -label "Turn off focus follow mouse on exit" -variable settings(mouseFocusOffAtExit)
$m3 add checkbutton -label "Turn on focus follow mouse at startup" -variable settings(mouseFocusOnAtStart)
$m3 add checkbutton -label "Auto open clipboard at startup" -variable settings(clipboardAtStart) -command {if {$settings(clipboardAtStart)} ClipboardManager}
$m3 add separator
$m3 add radiobutton -label "Auto reset focus to main: Off" -value 0 -variable settings(autoResetFocusToMain)
$m3 add radiobutton -label "Auto reset focus to main: after 0.5 sec" -value 0.5 -variable settings(autoResetFocusToMain)
$m3 add radiobutton -label "Auto reset focus to main: after 1 sec" -value 1 -variable settings(autoResetFocusToMain)
$m3 add radiobutton -label "Auto reset focus to main: after 2 sec" -value 2 -variable settings(autoResetFocusToMain)
$m3 add radiobutton -label "Auto reset focus to main: after 3 sec" -value 3 -variable settings(autoResetFocusToMain)
if {$hasRR} {
$m3 add checkbutton -label "Auto reset after direct RR keys" -variable settings(autoResetDirect)
$m3 add checkbutton -label "Always focus (if mixing click and RR)" -variable settings(rrAlwaysFocus)
}
$m3 add separator
$m3 add checkbutton -label "Pause when mouse is outside windows" -variable settings(mouseOutsideWindowsPauses)
$m3 add checkbutton -label "Focus back when mouse in game window" -variable settings(mouseInsideGameWindowFocuses)
menu .mbar.help -tearoff 0
.mbar add cascade -label Help -menu .mbar.help
.mbar.help add command -label "Online help..." -command Help
.mbar.help add separator
.mbar.help add command -label "Track mouse..." -command MouseTracking
.mbar.help add separator
.mbar.help add command -label "Get the newest binary release..." -command Releases
.mbar.help add command -label "Check for update" -command [list CheckForUpdates 0]
.mbar.help add command -label About -command About
}
proc MouseBroadcast {} {
global mouseBroadcast
set mouseBroadcast [expr {1-$mouseBroadcast}]
}
proc MouseTracking {} {
global settings mouseArea mouseCoords
set tw .mouseTracking
if {[winfo exists $tw]} {
wm state $tw normal
raise $tw
StartStopMouseTrack
return
}
toplevel $tw
wm title $tw "OMB Mouse Tracking"
grid [ttk::button $tw.bml -width 14 -text "Track mouse" -command StartStopMouseTrack] [entry $tw.emt -textvariable mouseCoords -width 14] -padx 4 -sticky w
tooltip $tw.bml "Start/Stop mouse tracking\nHotkey: $settings(hk,mouseTrack)"
grid [ttk::label $tw.la -text "Coords in area"] [entry $tw.ema -textvariable mouseArea -width 14] -padx 4 -sticky w
UpdateHandles
StartStopMouseTrack
}
proc CheckAutoKill {} {
global settings
if {!$settings(autoKillOn)} {
Debug "Auto kill is off"
return
}
foreach p [twapi::get_process_ids -name $settings(autoKillName)] {
set path [twapi::get_process_path $p]
Debug "Killing $settings(autoKillName): $p ($path)"
set newPath $path.bak
if {[file exists $path]} {
if {[catch {file rename -force $path $newPath} err]} {
OmbError "AutoKill rename error" "$err"
}
Debug "Renamed $path to $newPath"
}
Debug "Result: [twapi::end_process $p -wait 200 -force -exitcode -1]"
# We could also delete it but... lets not for now
#if {[file exists $newPath]} {
# file delete $newPath
# Debug "Deleted $newPath"
#}
}
}
proc ValidWindowSettingsN {n} {
global settings
expr {[info exists settings($n,posXY)]&&[info exists settings($n,size)]}
}
proc IsIn {x y n} {
global settings
if {![ValidWindowSettingsN $n]} {
return false
}
lassign $settings($n,posXY) wx1 wy1
lassign $settings($n,size) ww wh
set wx2 [expr {$wx1+$ww}]
set wy2 [expr {$wy1+$wh}]
expr {$x>=$wx1 && $x<=$wx2 && $y>=$wy1 && $y <=$wy2}
}
proc CoordsIn {mouseCoords} {
global settings
lassign $mouseCoords x y
for {set n 1} {$n<=$settings(numWindows)} {incr n 1} {
if {[IsIn $x $y $n]} {
return $n
}
}
return 0
}
proc MouseIsIn {} {
if {[catch {twapi::get_mouse_location} coords]} {
# expected in lock screen etc
#Debug "Can't get mouse coords: $coords"
return 0
}
CoordsIn $coords
}
proc ShouldPause {} {
if {[catch {twapi::get_mouse_location} coords]} {
# expected in lock screen etc
#Debug "Can't get mouse coords: $coords"
return 1
}
lassign $coords x y
set w [twapi::get_window_at_location $x $y]
set isOurs [IsOurs $w]
#Debug "For $x $y : $w : $isOurs"
list [expr {$isOurs<2}] $isOurs
}
proc MouseArea {mouseCoords} {
global settings
set n [CoordsIn $mouseCoords]
if {$n} {
return "Window $n"
} else {
return "Not in 1-$settings(numWindows)"
}
}
proc ClickWindowRel {n xp yp button} {
global settings slot2position
set p $slot2position($n)
# scale
lassign $settings($p,posXY) lx ly
lassign $settings($p,size) lw lh
set x [expr {round($lx+$xp*$lw)}]
set y [expr {round($ly+$yp*$lh)}]
Debug "Will click at $x $y for $n"
twapi::move_mouse $x $y
after $settings(mouseBroadcastDelay)
twapi::click_mouse_button $button
}
set clickInProgress ""
set mouseBeforeClick ""
proc MouseBroadcastCheck {} {
global mouseBeforeClick clickInProgress settings slot2position slot2handle
set VK_LBUTTON 0x01
set VK_RBUTTON 0x02
set W_KEY 0x57
if {[twapi::GetAsyncKeyState $VK_RBUTTON]>=1 || [twapi::GetAsyncKeyState $W_KEY]>1} {
set clickInProgress ""
return
}
if {[catch {twapi::get_mouse_location} lMouse]} {
# access denied while in lock screen etc
return
}
set state [twapi::GetAsyncKeyState $VK_LBUTTON]
if {$clickInProgress!="" && $state==0} {
set saveMousePos $lMouse
Debug "MOUSE_CLICK_RELEASE $clickInProgress vs $saveMousePos"
# return to the click pos and not current pos which seems to glitch at times
set saveMousePos $clickInProgress
lassign $clickInProgress x y
set clickInProgress ""