-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom_action.go
74 lines (65 loc) · 1.76 KB
/
custom_action.go
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
package maa
import (
"sync/atomic"
"github.com/MaaXYZ/maa-framework-go/internal/buffer"
)
var (
customActionCallbackID uint64
customActionCallbackAgents = make(map[uint64]CustomAction)
)
func registerCustomAction(action CustomAction) uint64 {
id := atomic.AddUint64(&customActionCallbackID, 1)
customActionCallbackAgents[id] = action
return id
}
func unregisterCustomAction(id uint64) bool {
if _, ok := customActionCallbackAgents[id]; !ok {
return false
}
delete(customActionCallbackAgents, id)
return true
}
type CustomActionArg struct {
TaskDetail *TaskDetail
CurrentTaskName string
CustomActionName string
CustomActionParam string
RecognitionDetail *RecognitionDetail
Box Rect
}
type CustomAction interface {
Run(ctx *Context, arg *CustomActionArg) bool
}
func _MaaCustomActionCallbackAgent(
context uintptr,
taskId int64,
currentTaskName, customActionName, customActionParam *byte,
recoId int64,
box uintptr,
transArg uintptr,
) uint64 {
// Here, we are simply passing the uint64 value as a pointer
// and will not actually dereference this pointer.
id := uint64(transArg)
action := customActionCallbackAgents[id]
ctx := &Context{handle: context}
tasker := ctx.GetTasker()
taskDetail := tasker.getTaskDetail(taskId)
recognitionDetail := tasker.getRecognitionDetail(recoId)
curBoxRectBuffer := buffer.NewRectBufferByHandle(box)
ok := action.Run(
&Context{handle: context},
&CustomActionArg{
TaskDetail: taskDetail,
CurrentTaskName: bytePtrToString(currentTaskName),
CustomActionName: bytePtrToString(customActionName),
CustomActionParam: bytePtrToString(customActionParam),
RecognitionDetail: recognitionDetail,
Box: curBoxRectBuffer.Get(),
},
)
if ok {
return 1
}
return 0
}