@@ -9,6 +9,23 @@ import (
9
9
"syscall"
10
10
11
11
"golang.org/x/sys/windows"
12
+ // walk
13
+ "github.com/lxn/walk"
14
+
15
+ //lint:ignore ST1001 standard behavior lxn/walk
16
+ . "github.com/lxn/walk/declarative"
17
+ )
18
+
19
+ type MyMainWindow struct {
20
+ * walk.MainWindow
21
+ * walk.NumberEdit // NumberEdit1
22
+ }
23
+
24
+ var (
25
+ TIMERRES int16
26
+ KILL_DWM = false
27
+ KILL_EXPLORER = false
28
+ DISABLE_IDLE = false
12
29
)
13
30
14
31
func killProcesses (pids []string ) {
@@ -39,30 +56,114 @@ func killProcesses(pids []string) {
39
56
}
40
57
}
41
58
59
+ // use taskkill for explorer, killProcesses() makes explorer restart itself
60
+ func killExplorer () {
61
+ exec .Command ("taskkill" , "/f" , "/im" , "explorer.exe" ).Run ()
62
+ }
63
+
42
64
func main () {
43
- // get config...
44
- c := GetConfig ()
65
+ var label * walk.Label
66
+ mw := new (MyMainWindow )
67
+ if err := (MainWindow {
68
+ AssignTo : & mw .MainWindow ,
69
+ Title : "GameUtil" ,
70
+ Size : Size {Width : 200 , Height : 110 },
71
+ Layout : VBox {},
72
+ Children : []Widget {
73
+ Label {
74
+ AssignTo : & label ,
75
+ Name : "Label" ,
76
+ Text : "Launch your game before clicking Start" ,
77
+ },
78
+ Composite {
79
+ Layout : Grid {Columns : 2 },
80
+ Children : []Widget {
81
+ Label {
82
+ Text : "Timer Resolution:" ,
83
+ ToolTipText : "In 100ns units. 0 to disable, 5000 for 0.5ms timer." ,
84
+ },
85
+ NumberEdit {
86
+ AssignTo : & mw .NumberEdit ,
87
+ Value : 5000 ,
88
+ Decimals : 0 ,
89
+ MinValue : 0 ,
90
+ MaxValue : 10000 ,
91
+ OnValueChanged : func () {
92
+ TIMERRES = int16 (mw .NumberEdit .Value ())
93
+ },
94
+ },
95
+ RadioButtonGroup {
96
+ Buttons : []RadioButton {
97
+ {
98
+ Text : "Kill DWM" ,
99
+ OnClicked : func () {
100
+ KILL_DWM = true
101
+ KILL_EXPLORER = false
102
+ },
103
+ },
104
+ {
105
+ Text : "Kill Explorer" ,
106
+ OnClicked : func () {
107
+ KILL_EXPLORER = true
108
+ KILL_DWM = false
109
+ },
110
+ },
111
+ },
112
+ },
113
+ Label {
114
+ Text : "Disable Idle" ,
115
+ },
116
+ CheckBox {
117
+ OnClicked : func () {
118
+ DISABLE_IDLE = ! DISABLE_IDLE
119
+ },
120
+ },
121
+ PushButton {
122
+ Text : "Start" ,
123
+ OnClicked : func () {
124
+ label .SetText ("Starting..." )
125
+ start ()
126
+ },
127
+ },
128
+ PushButton {
129
+ Text : "Restore" ,
130
+ OnClicked : func () {
131
+ restore ()
132
+ },
133
+ },
134
+ },
135
+ },
136
+ },
137
+ }).Create (); err != nil {
138
+ fmt .Println (err )
139
+ os .Exit (1 )
140
+ }
141
+ mw .Show ()
142
+ mw .Run ()
143
+ }
144
+
145
+ func start () {
45
146
var wp Processes
46
147
err := wp .getProcesses ()
47
148
if err != nil {
48
- panic (err )
149
+ fmt . Println (err )
49
150
}
50
- if c . KILL_EXPLORER {
151
+ if KILL_EXPLORER {
51
152
fmt .Println ("Killing explorer.." )
52
- pids := wp .findProcessIDByNames ([]string {"explorer.exe" })
53
- killProcesses (pids )
153
+ killExplorer ()
54
154
}
55
- if c . TIMERRES != 0 {
56
- NtSetTimerRes (c . TIMERRES )
155
+ if TIMERRES != 0 {
156
+ NtSetTimerRes (TIMERRES )
57
157
}
58
- if c . DISABLE_IDLE {
158
+ if DISABLE_IDLE {
59
159
err := exec .Command ("powercfg" , "-setacvalueindex" , "scheme_current" , "sub_processor" , "5d76a2ca-e8c0-402f-a133-2158492d58ad" , "1" ).Start ()
60
160
if err != nil {
61
161
fmt .Printf ("Could not disable idle: %v\n " , err )
62
162
}
63
163
}
64
- if c . KILL_DWM {
164
+ if KILL_DWM {
65
165
// Kill explorer and other processes
166
+ fmt .Println ("Killing DWM.." )
66
167
p2k := []string {"explorer.exe" , "searchapp.exe" , "shellexperiencehost.exe" , "searchui.exe" , "runtimebroker.exe" , "textinputhost.exe" , "dllhost.exe" , "wmiprvse.exe" }
67
168
pids := wp .findProcessIDByNames (p2k )
68
169
fmt .Println ("p2k" , pids )
@@ -79,20 +180,23 @@ func main() {
79
180
fmt .Println ("dwm" , pids )
80
181
killProcesses (pids )
81
182
}
183
+ }
82
184
83
- fmt .Println ("Done! Alt-Tab to your game. Once you are finished, press any key to restore default functionality." )
84
- var input string
85
- fmt .Scanln (& input )
86
-
185
+ func restore () {
186
+ var wp Processes
187
+ err := wp .getProcesses ()
188
+ if err != nil {
189
+ fmt .Println (err )
190
+ }
87
191
// restore explorer, resume winlogon, dwm etc.
88
192
// timer resolution will be returned back to previous value after process is closed
89
- if c . DISABLE_IDLE {
193
+ if DISABLE_IDLE {
90
194
err := exec .Command ("powercfg" , "-setacvalueindex" , "scheme_current" , "sub_processor" , "5d76a2ca-e8c0-402f-a133-2158492d58ad" , "0" ).Start ()
91
195
if err != nil {
92
196
fmt .Printf ("Could not enable idle: %v\n " , err )
93
197
}
94
198
}
95
- if c . KILL_DWM {
199
+ if KILL_DWM {
96
200
// Resume winlogon
97
201
fmt .Println ("Resuming winlogon.." )
98
202
pids := wp .findProcessIDByNames ([]string {"winlogon.exe" })
@@ -117,12 +221,20 @@ func main() {
117
221
os .Exit (0 )
118
222
}()
119
223
}
120
- if c .KILL_EXPLORER {
121
- fmt .Println ("Restarting explorer.." )
122
- err := exec .Command ("explorer.exe" ).Start ()
123
- if err != nil {
124
- fmt .Printf ("Explorer restart failed with %s\n " , err )
125
- }
224
+ if KILL_EXPLORER {
225
+ fmt .Println ("Starting explorer.." )
226
+ pids := wp .findProcessIDByNames ([]string {"explorer.exe" })
227
+ killProcesses (pids )
228
+ ch := make (chan os.Signal )
229
+ signal .Notify (ch , os .Interrupt , syscall .SIGTERM )
230
+ go func () {
231
+ <- ch
232
+ err := exec .Command ("explorer.exe" ).Start ()
233
+ if err != nil {
234
+ fmt .Printf ("Explorer restart failed with %s\n " , err )
235
+ }
236
+ }()
237
+ exec .Command ("explorer.exe" ).Start ()
126
238
}
127
239
os .Exit (0 )
128
240
}
0 commit comments