Skip to content

Commit 6525584

Browse files
committed
examples:wowjump.
1 parent 7b68b64 commit 6525584

File tree

8 files changed

+378
-4
lines changed

8 files changed

+378
-4
lines changed

examples/wowjump/jump.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
3+
import "sync"
4+
5+
var mux = sync.Mutex{}
6+
7+
var running = false
8+
var logouts []*Logout
9+
10+
var clicking = false

examples/wowjump/logout.go

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
package main
2+
3+
import (
4+
"github.com/lxn/win"
5+
"log"
6+
"math/rand"
7+
"time"
8+
)
9+
10+
type LogoutStatus int
11+
12+
const (
13+
// 正常
14+
NORMAL LogoutStatus = iota
15+
INPUT
16+
CHAR
17+
ENTERING
18+
)
19+
20+
type Logout struct {
21+
prevTime time.Time
22+
subTime time.Duration
23+
currentState LogoutStatus
24+
hwnd win.HWND
25+
}
26+
27+
func (l *Logout) Update() {
28+
switch l.currentState {
29+
case NORMAL:
30+
l.normal()
31+
case INPUT:
32+
l.input()
33+
case CHAR:
34+
l.char()
35+
case ENTERING:
36+
l.enter()
37+
}
38+
}
39+
40+
func (l *Logout) normal() {
41+
if l.subTime == 0 {
42+
l.subTime = time.Duration(rand.Int()%(config.NormalTime)*int(time.Second)) + time.Duration(config.NormalTime*int(time.Second))
43+
l.prevTime = time.Now()
44+
log.Println(l.hwnd, "挂机一会", l.subTime)
45+
}
46+
if time.Now().Sub(l.prevTime) > l.subTime {
47+
l.subTime = 0
48+
l.currentState = INPUT
49+
}
50+
}
51+
52+
func (l *Logout) input() {
53+
if l.subTime == 0 {
54+
if !l.TryGetWindow() {
55+
randomSleep(1111, 1111)
56+
}
57+
l.subTime = time.Duration(rand.Int()%(config.InputTime)*int(time.Second)) + time.Duration(config.InputTime*int(time.Second))
58+
l.prevTime = time.Now()
59+
log.Println(l.hwnd, "小退中。。。", l.subTime)
60+
if !l.logout() {
61+
l.subTime = 0
62+
}
63+
return
64+
}
65+
if time.Now().Sub(l.prevTime) > l.subTime {
66+
l.subTime = 0
67+
l.currentState = CHAR
68+
}
69+
}
70+
71+
func (l *Logout) char() {
72+
if l.subTime == 0 {
73+
l.subTime = time.Duration(rand.Int()%(config.CharWaitTime)*int(time.Second)) + time.Duration(config.CharWaitTime*int(time.Second))
74+
l.prevTime = time.Now()
75+
log.Println(l.hwnd, "角色界面等待一会。。。", l.subTime)
76+
}
77+
if time.Now().Sub(l.prevTime) > l.subTime {
78+
l.subTime = 0
79+
l.currentState = ENTERING
80+
}
81+
}
82+
func (l *Logout) enter() {
83+
if l.subTime == 0 {
84+
if !l.TryGetWindow() {
85+
randomSleep(1111, 1111)
86+
}
87+
l.subTime = time.Duration(rand.Int()%(config.EnterTime)*int(time.Second)) + time.Duration(config.EnterTime*int(time.Second))
88+
l.prevTime = time.Now()
89+
log.Println(l.hwnd, "正在进入游戏。。。", l.subTime)
90+
if !l.inputEnter() {
91+
l.subTime = 0
92+
}
93+
return
94+
}
95+
if time.Now().Sub(l.prevTime) > l.subTime {
96+
l.subTime = 0
97+
l.currentState = NORMAL
98+
}
99+
}
100+
101+
func (l *Logout) Reset() {
102+
l.currentState = NORMAL
103+
l.subTime = 0
104+
l.prevTime = time.Now()
105+
}
106+
107+
func (l *Logout) inputEnter() bool {
108+
if !l.CheckWindow() {
109+
return false
110+
}
111+
keybd_input(uint('\r'), false)
112+
randomSleep(211, 155)
113+
keybd_input(uint('\r'), true)
114+
return true
115+
}
116+
117+
func (l *Logout) logout() bool {
118+
if !l.CheckWindow() {
119+
return false
120+
}
121+
keybd_input(uint('\r'), false)
122+
randomSleep(211, 155)
123+
keybd_input(uint('\r'), true)
124+
randomSleep(211, 155)
125+
SendString("/logout", 333)
126+
randomSleep(211, 155)
127+
keybd_input(uint('\r'), false)
128+
randomSleep(111, 55)
129+
keybd_input(uint('\r'), true)
130+
return true
131+
}
132+
133+
func (l *Logout) IsValid() bool {
134+
return win.IsWindowVisible(l.hwnd)
135+
}
136+
137+
func (l *Logout) CheckWindow() bool {
138+
// 检查窗口
139+
if !l.IsValid() {
140+
return false
141+
}
142+
focus := win.GetForegroundWindow()
143+
if l.hwnd != focus {
144+
//log.Printf("FOCUS not WOW focus:%d WOW:%d focus WOW", focus, logout.hwnd)
145+
win.ShowWindow(l.hwnd, win.SW_NORMAL)
146+
win.SetActiveWindow(l.hwnd)
147+
win.SetForegroundWindow(l.hwnd)
148+
randomSleep(2000, 1000)
149+
}
150+
return true
151+
}
152+
153+
func (l *Logout) TryGetWindow() bool {
154+
focus := win.GetForegroundWindow()
155+
if focus != l.hwnd {
156+
win.ShowWindow(l.hwnd, win.SW_NORMAL)
157+
randomSleep(11, 22)
158+
win.SetActiveWindow(l.hwnd)
159+
randomSleep(11, 22)
160+
win.SetForegroundWindow(l.hwnd)
161+
randomSleep(11, 22)
162+
return false
163+
}
164+
return true
165+
}

examples/wowjump/main.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
)
1111

1212
var dlg *wingui.Dialog
13+
var out *wingui.Edit
1314

1415
// 防止进程多开,返回 true 表示进程已经开启
1516
func ProcessMutex(name string) bool {
@@ -32,6 +33,8 @@ func init() {
3233
}
3334
}
3435

36+
var btn *wingui.Button
37+
3538
// optional genereate resource IDs
3639
//go:generate go run github.com/whtiehack/wingui/tools/genids -filename ui/resource.h -packagename main
3740
func main() {
@@ -42,13 +45,17 @@ func main() {
4245
}
4346
dlg.SetIcon(IDI_ICON1)
4447
editLog, _ := dlg.NewEdit(IDE_LOG)
48+
out = editLog
4549
SetLogOutput(editLog)
4650
config.editNormaltime, _ = dlg.NewEdit(IDE_NORMAL_TIME)
4751
config.editEnterTime, _ = dlg.NewEdit(IDE_ENTER_TIME)
4852
config.editInputTime, _ = dlg.NewEdit(IDE_INPUT_TIME)
4953
config.editCharWaitTime, _ = dlg.NewEdit(IDE_CHAR_WAIT_TIME)
5054
config.InitVal()
55+
btn, _ = dlg.NewButton(IDB_RUN)
56+
btn.OnClicked = btnClick
5157
dlg.Show()
58+
// Make sure Tabstop can work.
5259
wingui.SetCurrentDialog(dlg.Handle())
5360
wingui.MessageLoop()
5461
log.Println("stoped")
@@ -65,10 +72,44 @@ func (m *MyLogoutput) Write(p []byte) (n int, err error) {
6572
if m.count >= 1000 {
6673
m.edit.SetText("")
6774
}
68-
m.edit.AppendText(string(p))
75+
m.edit.AppendText(string(p) + "\r\n")
6976
return
7077
}
7178
func SetLogOutput(edit *wingui.Edit) {
7279
m := &MyLogoutput{edit: edit}
7380
log.SetOutput(m)
7481
}
82+
83+
func btnClick() {
84+
if clicking {
85+
return
86+
}
87+
clicking = true
88+
defer func() { clicking = false }()
89+
mux.Lock()
90+
defer mux.Unlock()
91+
config.Save()
92+
running = !running
93+
//move.Retset()
94+
//jump.Reset()
95+
var text = "开启"
96+
if running {
97+
logouts = GetMultiLogout()
98+
if len(logouts) == 0 {
99+
running = !running
100+
log.Println("没有找到WOW窗口")
101+
return
102+
}
103+
out.SetText("")
104+
log.Printf("找到 %d 个 WOW窗口\n", len(logouts))
105+
text = "关闭"
106+
//str := skillKey.Text()
107+
//config.SkillKey = str
108+
//randomSkill.ParseSkillKey(str)
109+
log.Println("开始运行")
110+
} else {
111+
log.Println("已经停止运行")
112+
}
113+
config.EditEnable(!running)
114+
btn.SetText(text)
115+
}

examples/wowjump/multiwindows.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package main
2+
3+
import (
4+
"github.com/lxn/win"
5+
"github.com/whtiehack/wingui/user32"
6+
"log"
7+
"strconv"
8+
"syscall"
9+
)
10+
11+
func getHwnds() []win.HWND {
12+
hwndArr := make([]win.HWND, 0, 10)
13+
var curh win.HWND
14+
strArr := make([]string, 0, 10)
15+
for {
16+
// syscall.StringToUTF16Ptr("GxWindowClass")
17+
//curh = user32.FindWindowEx(0, curh, nil, syscall.StringToUTF16Ptr("ssl.csr - 记事本"))
18+
curh = user32.FindWindowEx(0, curh, syscall.StringToUTF16Ptr("GxWindowClass"), nil)
19+
if curh == 0 {
20+
break
21+
}
22+
hwndArr = append(hwndArr, curh)
23+
strArr = append(strArr, strconv.Itoa(int(curh)))
24+
}
25+
log.Println("hwndArr", hwndArr)
26+
return hwndArr
27+
}
28+
29+
func GetMultiLogout() []*Logout {
30+
arr := getHwnds()
31+
logouts := make([]*Logout, 0, 5)
32+
for _, hwnd := range arr {
33+
win.ShowWindow(hwnd, win.SW_NORMAL)
34+
win.SetActiveWindow(hwnd)
35+
win.SetForegroundWindow(hwnd)
36+
c := make(chan struct{}, 5)
37+
r := win.MessageBox(hwnd, syscall.StringToUTF16Ptr("是否要操作这个WoW窗口?"),
38+
syscall.StringToUTF16Ptr("确认"), win.MB_YESNO)
39+
log.Println("select ret", r)
40+
c <- struct{}{}
41+
if r != win.IDYES {
42+
continue
43+
}
44+
logouts = append(logouts, &Logout{hwnd: hwnd})
45+
}
46+
return logouts
47+
}

examples/wowjump/ui.syso

0 Bytes
Binary file not shown.

examples/wowjump/ui/ui.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
1717
IDD_DIALOG_MAIN DIALOG 0, 0, 300, 270
1818
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_GROUP | WS_POPUP | WS_SYSMENU
1919
EXSTYLE WS_EX_WINDOWEDGE
20-
CAPTION "Dialog"
20+
CAPTION "ħ�޷�����"
2121
FONT 8, "Ms Shell Dlg"
2222
{
2323
LTEXT "�޸���ʱ�佨�鶢�ſ�һ�£��᲻�������⡣\n<����>֮ǰ�������ֶ�С��һ�¡�", 0, 7, 222, 161, 17, SS_LEFT, WS_EX_LEFT

0 commit comments

Comments
 (0)