Skip to content

Commit 8315a80

Browse files
committed
Add GUI - WIP
1 parent 661b686 commit 8315a80

File tree

10 files changed

+166
-61
lines changed

10 files changed

+166
-61
lines changed

gameutil/WindowsProcess.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func (wp Processes) findProcessIDByNames(names []string) []string {
6464
}
6565
return result
6666
}
67+
6768
func newWindowsProcess(e *windows.ProcessEntry32) Process {
6869
// Find when the string ends for decoding
6970
end := 0

gameutil/build.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
go build -v -ldflags="-w -s" -gcflags "-dwarf=false" .
1+
go build -v -tags walk_use_cgo -ldflags="-w -s" -gcflags "-dwarf=false" .
22
pause

gameutil/config.go

Lines changed: 0 additions & 30 deletions
This file was deleted.

gameutil/config.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

gameutil/gameutil.manifest

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
3+
<assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="SomeFunkyNameHere" type="win32"/>
4+
<dependency>
5+
<dependentAssembly>
6+
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
7+
</dependentAssembly>
8+
</dependency>
9+
<application xmlns="urn:schemas-microsoft-com:asm.v3">
10+
<windowsSettings>
11+
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
12+
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True</dpiAware>
13+
</windowsSettings>
14+
</application>
15+
</assembly>

gameutil/go.mod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ module gameutil
33
go 1.17
44

55
require golang.org/x/sys v0.0.0-20211204120058-94396e421777
6+
7+
require (
8+
github.com/lxn/walk v0.0.0-20210112085537-c389da54e794 // indirect
9+
github.com/lxn/win v0.0.0-20210218163916-a377121e959e // indirect
10+
gopkg.in/Knetic/govaluate.v3 v3.0.0 // indirect
11+
)

gameutil/go.sum

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
github.com/lxn/walk v0.0.0-20210112085537-c389da54e794 h1:NVRJ0Uy0SOFcXSKLsS65OmI1sgCCfiDUPj+cwnH7GZw=
2+
github.com/lxn/walk v0.0.0-20210112085537-c389da54e794/go.mod h1:E23UucZGqpuUANJooIbHWCufXvOcT6E7Stq81gU+CSQ=
3+
github.com/lxn/win v0.0.0-20210218163916-a377121e959e h1:H+t6A/QJMbhCSEH5rAuRxh+CtW96g0Or0Fxa9IKr4uc=
4+
github.com/lxn/win v0.0.0-20210218163916-a377121e959e/go.mod h1:KxxjdtRkfNoYDCUP5ryK7XJJNTnpC8atvtmTheChOtk=
5+
golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
16
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881 h1:TyHqChC80pFkXWraUUf6RuB5IqFdQieMLwwCJokV2pc=
27
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
38
golang.org/x/sys v0.0.0-20211204120058-94396e421777 h1:QAkhGVjOxMa+n4mlsAWeAU+BMZmimQAaNiMu+iUi94E=
49
golang.org/x/sys v0.0.0-20211204120058-94396e421777/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
10+
gopkg.in/Knetic/govaluate.v3 v3.0.0 h1:18mUyIt4ZlRlFZAAfVetz4/rzlJs9yhN+U02F4u1AOc=
11+
gopkg.in/Knetic/govaluate.v3 v3.0.0/go.mod h1:csKLBORsPbafmSCGTEh3U7Ozmsuq8ZSIlKk1bcqph0E=

gameutil/main.go

Lines changed: 134 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@ import (
99
"syscall"
1010

1111
"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
1229
)
1330

1431
func killProcesses(pids []string) {
@@ -39,30 +56,114 @@ func killProcesses(pids []string) {
3956
}
4057
}
4158

59+
// use taskkill for explorer, killProcesses() makes explorer restart itself
60+
func killExplorer() {
61+
exec.Command("taskkill", "/f", "/im", "explorer.exe").Run()
62+
}
63+
4264
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() {
45146
var wp Processes
46147
err := wp.getProcesses()
47148
if err != nil {
48-
panic(err)
149+
fmt.Println(err)
49150
}
50-
if c.KILL_EXPLORER {
151+
if KILL_EXPLORER {
51152
fmt.Println("Killing explorer..")
52-
pids := wp.findProcessIDByNames([]string{"explorer.exe"})
53-
killProcesses(pids)
153+
killExplorer()
54154
}
55-
if c.TIMERRES != 0 {
56-
NtSetTimerRes(c.TIMERRES)
155+
if TIMERRES != 0 {
156+
NtSetTimerRes(TIMERRES)
57157
}
58-
if c.DISABLE_IDLE {
158+
if DISABLE_IDLE {
59159
err := exec.Command("powercfg", "-setacvalueindex", "scheme_current", "sub_processor", "5d76a2ca-e8c0-402f-a133-2158492d58ad", "1").Start()
60160
if err != nil {
61161
fmt.Printf("Could not disable idle: %v\n", err)
62162
}
63163
}
64-
if c.KILL_DWM {
164+
if KILL_DWM {
65165
// Kill explorer and other processes
166+
fmt.Println("Killing DWM..")
66167
p2k := []string{"explorer.exe", "searchapp.exe", "shellexperiencehost.exe", "searchui.exe", "runtimebroker.exe", "textinputhost.exe", "dllhost.exe", "wmiprvse.exe"}
67168
pids := wp.findProcessIDByNames(p2k)
68169
fmt.Println("p2k", pids)
@@ -79,20 +180,23 @@ func main() {
79180
fmt.Println("dwm", pids)
80181
killProcesses(pids)
81182
}
183+
}
82184

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+
}
87191
// restore explorer, resume winlogon, dwm etc.
88192
// timer resolution will be returned back to previous value after process is closed
89-
if c.DISABLE_IDLE {
193+
if DISABLE_IDLE {
90194
err := exec.Command("powercfg", "-setacvalueindex", "scheme_current", "sub_processor", "5d76a2ca-e8c0-402f-a133-2158492d58ad", "0").Start()
91195
if err != nil {
92196
fmt.Printf("Could not enable idle: %v\n", err)
93197
}
94198
}
95-
if c.KILL_DWM {
199+
if KILL_DWM {
96200
// Resume winlogon
97201
fmt.Println("Resuming winlogon..")
98202
pids := wp.findProcessIDByNames([]string{"winlogon.exe"})
@@ -117,12 +221,20 @@ func main() {
117221
os.Exit(0)
118222
}()
119223
}
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()
126238
}
127239
os.Exit(0)
128240
}

gameutil/rsrc.syso

1.05 KB
Binary file not shown.

gameutil/win32api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ var (
2424
func SuspendProc(pid uint32) {
2525
handle, err := windows.OpenProcess(0x1F0FFF, false, pid)
2626
if err != nil {
27-
panic(err)
27+
println(err)
2828
}
2929
procNtSuspendProcess.Call(uintptr(handle))
3030
}
3131

3232
func NtResumeProcess(pid uint32) {
3333
handle, err := windows.OpenProcess(0x1F0FFF, false, pid)
3434
if err != nil {
35-
panic(err)
35+
println(err)
3636
}
3737
procNtResumeProcess.Call(uintptr(handle))
3838
}

0 commit comments

Comments
 (0)