-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModMain.cs
More file actions
101 lines (86 loc) · 3.13 KB
/
Copy pathModMain.cs
File metadata and controls
101 lines (86 loc) · 3.13 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using GooseShared;
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms; // for Cursor
public class ModMain : IMod
{
private readonly TimeSpan _idleThreshold = TimeSpan.FromMinutes(2);
private bool _aiTriggered = false, _bubbleAttached = false;
// — click‐count fields —
private int _clickCount = 0;
private DateTime _lastClickTime = DateTime.MinValue;
private const int MaxClickIntervalMs = 500; // max ms between taps
private const float ClickRadius = 50f; // px tolerance
[DllImport("User32.dll")]
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
[DllImport("user32.dll")]
private static extern short GetAsyncKeyState(int vKey);
[StructLayout(LayoutKind.Sequential)]
private struct LASTINPUTINFO { public uint cbSize, dwTime; }
public void Init()
{
InjectionPoints.PostTickEvent += OnTick;
}
private void OnTick(GooseEntity goose)
{
// Attach speech‐bubble renderer once
if (!_bubbleAttached)
{
goose.render += SpeechBubble.Draw;
_bubbleAttached = true;
}
// Idle trigger
CheckIdle(goose);
// Triple‐click trigger
CheckClicks(goose);
}
private void CheckIdle(GooseEntity goose)
{
if (!_aiTriggered && GetIdleTime() > _idleThreshold)
{
new TaskAIInteraction().RunTask(goose);
_aiTriggered = true;
}
else if (GetIdleTime() < TimeSpan.FromSeconds(10))
{
_aiTriggered = false;
}
}
private void CheckClicks(GooseEntity goose)
{
// Only on mouse‐down edge
const int VK_LBUTTON = 0x01;
bool isDown = (GetAsyncKeyState(VK_LBUTTON) & 0x8000) != 0;
if (isDown && _lastClickTime != DateTime.MinValue && (DateTime.Now - _lastClickTime).TotalMilliseconds < 50)
return; // still held
if (isDown)
{
var now = DateTime.Now;
// reset if too slow
if ((now - _lastClickTime).TotalMilliseconds > MaxClickIntervalMs)
_clickCount = 0;
// get cursor pos in screen coords
var cursor = Cursor.Position;
// game coords are also screen coords for Desktop Goose
float dx = cursor.X - goose.position.x;
float dy = cursor.Y - goose.position.y;
if (dx * dx + dy * dy < ClickRadius * ClickRadius)
{
_clickCount++;
if (_clickCount >= 3)
{
new TaskAIInteraction().RunTask(goose);
_clickCount = 0;
}
}
_lastClickTime = now;
}
}
private TimeSpan GetIdleTime()
{
var lastIn = new LASTINPUTINFO { cbSize = (uint)Marshal.SizeOf(typeof(LASTINPUTINFO)) };
GetLastInputInfo(ref lastIn);
uint idleMs = (uint)(Environment.TickCount - lastIn.dwTime);
return TimeSpan.FromMilliseconds(idleMs);
}
}