-
Notifications
You must be signed in to change notification settings - Fork 0
/
please.go
60 lines (53 loc) · 1.56 KB
/
please.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
package please
import (
"github.com/Zyko0/please/internal/frame"
"github.com/Zyko0/please/internal/locker"
"github.com/Zyko0/please/internal/patch"
"github.com/Zyko0/please/internal/runtime"
"github.com/Zyko0/please/metrics"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/text"
)
var (
patches []*patch.Patch
)
func init() {
// Ensure frame tick package is initialized
_ = frame.Current()
patches = []*patch.Patch{
patch.NewPatchMethod(&ebiten.Image{}, "DrawImage", patch.DrawImageReplacer),
patch.NewPatchMethod(&ebiten.Image{}, "DrawTriangles", patch.DrawTrianglesReplacer),
patch.NewPatchMethod(&ebiten.Image{}, "DrawRectShader", patch.DrawRectShaderReplacer),
patch.NewPatchFunc(text.DrawWithOptions, patch.TextDrawReplacer),
patch.NewPatchMethod(&ebiten.Image{}, "DrawTrianglesShader", patch.DrawTrianglesShaderReplacer),
patch.NewPatchFunc(ebiten.NewImage, patch.NewImageReplacer),
patch.NewPatchFunc(ebiten.NewImageWithOptions, patch.NewImageWithOptionsReplacer),
}
// Set patches reference internally to allow for live unpatching
patch.SetTextPatch(patches[3])
patch.SetTrianglesShaderPatch(patches[4])
patch.SetNewImagePatch(patches[5])
patch.SetNewImageWithOptionsPatch(patches[6])
}
// Sure!
func GlitchMe() {
locker.Lock()
defer locker.Unlock()
for _, p := range patches {
p.Enable()
}
}
// :(
func DontGlitchMe() {
locker.Lock()
defer locker.Unlock()
for _, p := range patches {
p.Disable()
}
}
// Fine..
func GiveMeSomethingUseful() *metrics.Metrics {
m := &metrics.Metrics{}
runtime.FillMetrics(m)
return m
}